From b916d59092ea2d460620a5f65c4bddbe3fc253cf Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sun, 25 Jan 2015 09:51:49 +0100 Subject: [PATCH] Added credentials to SMTP handling --- Utility/Communications/CommsTransmitterMail.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Utility/Communications/CommsTransmitterMail.cs b/Utility/Communications/CommsTransmitterMail.cs index 0e0dadbb..b407aaf2 100644 --- a/Utility/Communications/CommsTransmitterMail.cs +++ b/Utility/Communications/CommsTransmitterMail.cs @@ -15,6 +15,8 @@ namespace Swarmops.Utility.Communications private static string _smtpServerCache = string.Empty; private static int _smtpPortCache = 25; + private static string _smtpUserCache = string.Empty; + private static string _smtpPasswordCache = string.Empty; private static DateTime _cacheReloadTime = DateTime.MinValue; public void Transmit (PayloadEnvelope envelope, Person person) @@ -54,13 +56,18 @@ namespace Swarmops.Utility.Communications string smtpServer = _smtpServerCache; int smtpPort = _smtpPortCache; + string smtpUser = _smtpUserCache; + string smtpPassword = _smtpPasswordCache; DateTime now = DateTime.Now; if (now > _cacheReloadTime) { - smtpServer = SystemSettings.SmtpHost; - smtpPort = SystemSettings.SmtpPort; + smtpServer = _smtpServerCache = SystemSettings.SmtpHost; + smtpPort = _smtpPortCache = SystemSettings.SmtpPort; + smtpUser = _smtpUserCache = SystemSettings.SmtpUser; + smtpPassword = _smtpPasswordCache = SystemSettings.SmtpPassword; + _cacheReloadTime = now.AddMinutes (5); } @@ -73,8 +80,10 @@ namespace Swarmops.Utility.Communications } SmtpClient mailClient = new SmtpClient (smtpServer, smtpPort); - - // TODO: SMTP Server login credentials + if (!string.IsNullOrEmpty(smtpUser)) + { + mailClient.Credentials = new System.Net.NetworkCredential(smtpUser, smtpPassword); + } try {