1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2025-02-07 15:02:54 +00:00

SmtpProvider will throw on exceptions, instead of returning false.

This commit is contained in:
Mark McDowall 2012-04-29 22:36:49 -07:00
parent 2a8fab7ef9
commit b626dc2435

View file

@ -21,7 +21,7 @@ public SmtpProvider(ConfigProvider configProvider)
_configProvider = configProvider;
}
public virtual bool SendEmail(string subject, string body, bool htmlBody = false)
public virtual void SendEmail(string subject, string body, bool htmlBody = false)
{
//Create the Email message
var email = new MailMessage();
@ -54,7 +54,7 @@ public virtual bool SendEmail(string subject, string body, bool htmlBody = false
credentials = new NetworkCredential(username, password);
//Send the email
return Send(email, _configProvider.SmtpServer, _configProvider.SmtpPort, _configProvider.SmtpUseSsl, credentials);
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)
@ -90,11 +90,19 @@ public virtual bool SendTestEmail(string server, int port, bool ssl, string user
credentials = new NetworkCredential(username, password);
//Send the email
return Send(email, server, port, ssl, credentials);
try
{
Send(email, server, port, ssl, credentials);
}
catch(Exception ex)
{
Logger.TraceException("Failed to send test email", ex);
return false;
}
return true;
}
//TODO: make this throw instead of return false.
public virtual bool Send(MailMessage email, string server, int port, bool ssl, NetworkCredential credentials)
public virtual void Send(MailMessage email, string server, int port, bool ssl, NetworkCredential credentials)
{
try
{
@ -109,15 +117,12 @@ public virtual bool Send(MailMessage email, string server, int port, bool ssl, N
//Send the email
smtp.Send(email);
return true;
}
catch (Exception ex)
{
Logger.Error("There was an error sending an email.");
Logger.TraceException(ex.Message, ex);
return false;
Logger.ErrorException("There was an error sending an email.", ex);
throw;
}
}
}