diff --git a/NzbDrone.Core/Providers/SmtpProvider.cs b/NzbDrone.Core/Providers/SmtpProvider.cs
index 753971cac..2ff2eb26b 100644
--- a/NzbDrone.Core/Providers/SmtpProvider.cs
+++ b/NzbDrone.Core/Providers/SmtpProvider.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Net.Mail;
using System.Text;
using NLog;
@@ -21,38 +22,89 @@ namespace NzbDrone.Core.Providers
}
public virtual bool SendEmail(string subject, string body, bool htmlBody = false)
+ {
+ //Create the Email message
+ var email = new MailMessage();
+
+ //Set the addresses
+ email.From = new MailAddress(_configProvider.SmtpFromAddress);
+
+ //Allow multiple to addresses (split on each comma)
+ foreach (var toAddress in _configProvider.SmtpToAddresses.Split(','))
+ {
+ email.To.Add(toAddress.Trim());
+ }
+
+ //Set the Subject
+ email.Subject = subject;
+
+ //Set the Body
+ email.Body = body;
+
+ //Html Body
+ email.IsBodyHtml = htmlBody;
+
+ //Handle credentials
+ var username = _configProvider.SmtpUsername;
+ var password = _configProvider.SmtpPassword;
+
+ NetworkCredential credentials = null;
+
+ if (!String.IsNullOrWhiteSpace(username))
+ credentials = new NetworkCredential(username, password);
+
+ //Send the email
+ return Send(email, _configProvider.SmtpServer, _configProvider.SmtpPort, _configProvider.SmtpUseSsl, credentials);
+ }
+
+ public virtual bool SendTestEmail(string server, int port, bool ssl, string username, string password, string fromAddress, string toAddresses)
+ {
+ var subject = "NzbDrone SMTP Test Notification";
+ var body = "This is a test email from NzbDrone, if you received this message you properly configured your SMTP settings! (Now save them!)";
+
+ //Create the Email message
+ var email = new MailMessage();
+
+ //Set the addresses
+ email.From = new MailAddress(fromAddress);
+
+ //Allow multiple to addresses (split on each comma)
+ foreach (var toAddress in toAddresses.Split(','))
+ {
+ email.To.Add(toAddress.Trim());
+ }
+
+ //Set the Subject
+ email.Subject = subject;
+
+ //Set the Body
+ email.Body = body;
+
+ //Html Body
+ email.IsBodyHtml = false;
+
+ //Handle credentials
+ NetworkCredential credentials = null;
+
+ if (!String.IsNullOrWhiteSpace(username))
+ credentials = new NetworkCredential(username, password);
+
+ //Send the email
+ return Send(email, _configProvider.SmtpServer, _configProvider.SmtpPort, _configProvider.SmtpUseSsl, credentials);
+ }
+
+ public virtual bool Send(MailMessage email, string server, int port, bool ssl, NetworkCredential credentials)
{
try
{
- //Create the Email message
- var email = new MailMessage();
-
- //Set the addresses
- email.From = new MailAddress(_configProvider.SmtpFromAddress);
-
- //Allow multiple to addresses (split on each comma)
- foreach (var toAddress in _configProvider.SmtpToAddresses.Split(','))
- {
- email.To.Add(toAddress.Trim());
- }
-
- //Set the Subject
- email.Subject = subject;
-
- //Set the Body
- email.Body = body;
-
- //Html Body
- email.IsBodyHtml = htmlBody;
-
//Create the SMTP connection
- var smtp = new SmtpClient(_configProvider.SmtpServer, _configProvider.SmtpPort);
+ var smtp = new SmtpClient(server, port);
//Enable SSL
- smtp.EnableSsl = true;
+ smtp.EnableSsl = ssl;
//Credentials
- smtp.Credentials = new System.Net.NetworkCredential(_configProvider.SmtpUsername, _configProvider.SmtpPassword);
+ smtp.Credentials = credentials;
//Send the email
smtp.Send(email);
@@ -64,9 +116,8 @@ namespace NzbDrone.Core.Providers
{
Logger.Error("There was an error sending an email.");
Logger.TraceException(ex.Message, ex);
+ return false;
}
-
- return false;
}
}
}
diff --git a/NzbDrone.Web/Controllers/CommandController.cs b/NzbDrone.Web/Controllers/CommandController.cs
index e401f01a4..ecc0fc92d 100644
--- a/NzbDrone.Web/Controllers/CommandController.cs
+++ b/NzbDrone.Web/Controllers/CommandController.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
+using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Jobs;
@@ -13,11 +14,16 @@ namespace NzbDrone.Web.Controllers
{
private readonly JobProvider _jobProvider;
private readonly SabProvider _sabProvider;
+ private readonly SmtpProvider _smtpProvider;
- public CommandController(JobProvider jobProvider, SabProvider sabProvider)
+ private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
+
+ public CommandController(JobProvider jobProvider, SabProvider sabProvider,
+ SmtpProvider smtpProvider)
{
_jobProvider = jobProvider;
_sabProvider = sabProvider;
+ _smtpProvider = smtpProvider;
}
public JsonResult RssSync()
@@ -58,9 +64,19 @@ namespace NzbDrone.Web.Controllers
catch (Exception ex)
{
- //Todo: Log the error
- throw;
+ Logger.Warn("Unable to get Categories from SABnzbd");
+ Logger.DebugException(ex.Message, ex);
+ return Json(new NotificationResult { Title = "Failed", Text = "Unable to get SABnzbd Categories", NotificationType = NotificationType.Error });
}
}
+
+ [HttpPost]
+ public JsonResult SendTestEmail(string server, int port, bool ssl, string username, string password, string fromAddress, string toAddresses)
+ {
+ if (_smtpProvider.SendTestEmail(server, port, ssl, username, password, fromAddress, toAddresses))
+ return Json(new NotificationResult { Title = "Successfully sent test email." });
+
+ return Json(new NotificationResult { Title = "Failed", Text = "Unable to send Email, please check your settings", NotificationType = NotificationType.Error });
+ }
}
}
diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs
index 84bf6f023..eb6f0e707 100644
--- a/NzbDrone.Web/Controllers/SettingsController.cs
+++ b/NzbDrone.Web/Controllers/SettingsController.cs
@@ -160,7 +160,17 @@ namespace NzbDrone.Web.Controllers
XbmcCleanLibrary = _configProvider.XbmcCleanLibrary,
XbmcHosts = _configProvider.XbmcHosts,
XbmcUsername = _configProvider.XbmcUsername,
- XbmcPassword = _configProvider.XbmcPassword
+ XbmcPassword = _configProvider.XbmcPassword,
+ SmtpEnabled = _externalNotificationProvider.GetSettings(typeof(Smtp)).Enable,
+ SmtpNotifyOnGrab = _configProvider.SmtpNotifyOnGrab,
+ SmtpNotifyOnDownload = _configProvider.SmtpNotifyOnGrab,
+ SmtpServer = _configProvider.SmtpServer,
+ SmtpPort = _configProvider.SmtpPort,
+ SmtpUseSsl = _configProvider.SmtpUseSsl,
+ SmtpUsername = _configProvider.SmtpUsername,
+ SmtpPassword = _configProvider.SmtpPassword,
+ SmtpFromAddress = _configProvider.SmtpFromAddress,
+ SmtpToAddresses = _configProvider.SmtpToAddresses
};
return View(model);
@@ -433,6 +443,21 @@ namespace NzbDrone.Web.Controllers
_configProvider.XbmcUsername = data.XbmcUsername;
_configProvider.XbmcPassword = data.XbmcPassword;
+ //SMTP
+ var smtpSettings = _externalNotificationProvider.GetSettings(typeof (Smtp));
+ smtpSettings.Enable = data.SmtpEnabled;
+ _externalNotificationProvider.SaveSettings(smtpSettings);
+
+ _configProvider.SmtpNotifyOnGrab = data.SmtpNotifyOnGrab;
+ _configProvider.SmtpNotifyOnGrab = data.SmtpNotifyOnDownload;
+ _configProvider.SmtpServer = data.SmtpServer;
+ _configProvider.SmtpPort = data.SmtpPort;
+ _configProvider.SmtpUseSsl = data.SmtpUseSsl;
+ _configProvider.SmtpUsername = data.SmtpUsername;
+ _configProvider.SmtpPassword = data.SmtpPassword;
+ _configProvider.SmtpFromAddress = data.SmtpFromAddress;
+ _configProvider.SmtpToAddresses = data.SmtpToAddresses;
+
return GetSuccessResult();
}
diff --git a/NzbDrone.Web/Models/NotificationSettingsModel.cs b/NzbDrone.Web/Models/NotificationSettingsModel.cs
index 27e2026b6..7d3cd39f3 100644
--- a/NzbDrone.Web/Models/NotificationSettingsModel.cs
+++ b/NzbDrone.Web/Models/NotificationSettingsModel.cs
@@ -5,6 +5,7 @@ namespace NzbDrone.Web.Models
{
public class NotificationSettingsModel
{
+ //XBMC
[DisplayName("Enabled")]
[Description("Enable notifications for XBMC?")]
public bool XbmcEnabled { get; set; }
@@ -42,5 +43,59 @@ namespace NzbDrone.Web.Models
[Description("XBMC webserver password")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public string XbmcPassword { get; set; }
+
+ //SMTP
+ [DisplayName("Enabled")]
+ [Description("Enable SMTP notifications?")]
+ public bool SmtpEnabled { get; set; }
+
+ [DisplayName("Notify on Grab")]
+ [Description("Send notification when episode is sent to SABnzbd?")]
+ public bool SmtpNotifyOnGrab { get; set; }
+
+ [DisplayName("Notify on Download")]
+ [Description("Send notification when episode is downloaded?")]
+ public bool SmtpNotifyOnDownload { get; set; }
+
+ [DataType(DataType.Text)]
+ [DisplayName("Server")]
+ [Description("SMTP Server Hostname")]
+ [DisplayFormat(ConvertEmptyStringToNull = false)]
+ public string SmtpServer{ get; set; }
+
+ [DataType(DataType.Text)]
+ [DisplayName("Port")]
+ [Description("SMTP Server Port")]
+ [DisplayFormat(ConvertEmptyStringToNull = false)]
+ public int SmtpPort { get; set; }
+
+ [DisplayName("SSL")]
+ [Description("Does the SMTP Server use SSL?")]
+ [DisplayFormat(ConvertEmptyStringToNull = false)]
+ public bool SmtpUseSsl { get; set; }
+
+ [DataType(DataType.Text)]
+ [DisplayName("Username")]
+ [Description("SMTP Server authentication username")]
+ [DisplayFormat(ConvertEmptyStringToNull = false)]
+ public string SmtpUsername { get; set; }
+
+ [DataType(DataType.Text)]
+ [DisplayName("Password")]
+ [Description("SMTP Server authentication password")]
+ [DisplayFormat(ConvertEmptyStringToNull = false)]
+ public string SmtpPassword { get; set; }
+
+ [DataType(DataType.Text)]
+ [DisplayName("Send From Address")]
+ [Description("Sender Email address")]
+ [DisplayFormat(ConvertEmptyStringToNull = false)]
+ public string SmtpFromAddress { get; set; }
+
+ [DataType(DataType.Text)]
+ [DisplayName("Send To Addresses")]
+ [Description("Comma separated list of addresses to email")]
+ [DisplayFormat(ConvertEmptyStringToNull = false)]
+ public string SmtpToAddresses { get; set; }
}
}
\ No newline at end of file
diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj
index 810f1e238..615ded070 100644
--- a/NzbDrone.Web/NzbDrone.Web.csproj
+++ b/NzbDrone.Web/NzbDrone.Web.csproj
@@ -932,6 +932,12 @@
+
+
+
+
+
+