add config to enable tls and ssl

master
Christopher 2020-06-30 11:50:25 +02:00
parent ab7ed113f3
commit 2b647f41aa
1 changed files with 21 additions and 5 deletions

View File

@ -1,4 +1,5 @@
using MailKit.Net.Smtp;
using MailKit.Security;
using MimeKit;
using Mono.Addins;
using Nini.Config;
@ -28,13 +29,15 @@ namespace OpenSim.Modules.EMail
private String SMTP_SERVER_PASSWORD = null;
private String SMTP_SERVER_SENDER = null;
private int SMTP_SERVER_PORT = 25;
private bool SMTP_SERVER_ENCRYPTION = false;
private bool SMTP_SERVER_SSL = false;
private bool SMTP_SERVER_TLS = false;
private String IMAP_SERVER_HOSTNAME = null;
private String IMAP_SERVER_LOGIN = null;
private String IMAP_SERVER_PASSWORD = null;
private int IMAP_SERVER_PORT = 25;
private bool IMAP_SERVER_ENCRYPTION = false;
private bool IMAP_SERVER_SSL = false;
private bool IMAP_SERVER_TLS = false;
#region ISharedRegionModule
public string Name
@ -78,14 +81,16 @@ namespace OpenSim.Modules.EMail
SMTP_SERVER_HOSTNAME = m_config.Configs["Mail"].GetString("SMTP_SERVER_HOSTNAME", "127.0.0.1");
SMTP_SERVER_PORT = m_config.Configs["Mail"].GetInt("SMTP_SERVER_PORT", 25);
SMTP_SERVER_ENCRYPTION = m_config.Configs["Mail"].GetBoolean("SMTP_SERVER_ENCRYPTION", false);
SMTP_SERVER_SSL = m_config.Configs["Mail"].GetBoolean("SMTP_SERVER_SSL", false);
SMTP_SERVER_TLS = m_config.Configs["Mail"].GetBoolean("SMTP_SERVER_TLS", false);
SMTP_SERVER_LOGIN = m_config.Configs["Mail"].GetString("SMTP_SERVER_LOGIN", "lsl@localhost");
SMTP_SERVER_PASSWORD = m_config.Configs["Mail"].GetString("SMTP_SERVER_PASSWORD", "");
SMTP_SERVER_SENDER = m_config.Configs["Mail"].GetString("SMTP_SERVER_SENDER", "");
IMAP_SERVER_HOSTNAME = m_config.Configs["Mail"].GetString("IMAP_SERVER_HOSTNAME", "127.0.0.1");
IMAP_SERVER_PORT = m_config.Configs["Mail"].GetInt("IMAP_SERVER_PORT", 25);
IMAP_SERVER_ENCRYPTION = m_config.Configs["Mail"].GetBoolean("IMAP_SERVER_ENCRYPTION", false);
SMTP_SERVER_SSL = m_config.Configs["Mail"].GetBoolean("IMAP_SERVER_SSL", false);
SMTP_SERVER_TLS = m_config.Configs["Mail"].GetBoolean("IMAP_SERVER_TLS", false);
IMAP_SERVER_LOGIN = m_config.Configs["Mail"].GetString("IMAP_SERVER_LOGIN", "lsl@localhost");
IMAP_SERVER_PASSWORD = m_config.Configs["Mail"].GetString("IMAP_SERVER_PASSWORD", "");
}
@ -120,7 +125,18 @@ namespace OpenSim.Modules.EMail
using (var client = new SmtpClient())
{
client.Connect(SMTP_SERVER_HOSTNAME, SMTP_SERVER_PORT, SMTP_SERVER_ENCRYPTION);
if (SMTP_SERVER_SSL == true)
{
client.Connect(SMTP_SERVER_HOSTNAME, SMTP_SERVER_PORT, SecureSocketOptions.Auto);
}
else if(SMTP_SERVER_TLS == true)
{
client.Connect(SMTP_SERVER_HOSTNAME, SMTP_SERVER_PORT, SecureSocketOptions.StartTlsWhenAvailable);
}
else
{
client.Connect(SMTP_SERVER_HOSTNAME, SMTP_SERVER_PORT, SecureSocketOptions.None);
}
client.Authenticate(SMTP_SERVER_LOGIN, SMTP_SERVER_PASSWORD);