mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 05:53:33 -07:00
Added SMTP settings editing to the UI.
Added testing of SMTP settings to the settings page. Cleaned up some extraneous lines of JS and HTML.
This commit is contained in:
parent
9957aef811
commit
2c93a27962
13 changed files with 368 additions and 107 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue