|
|
|
@ -83,23 +83,6 @@ namespace NzbDrone.Core.Notifications.Email
|
|
|
|
|
return new ValidationResult(failures);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ValidationFailure Test(EmailSettings settings)
|
|
|
|
|
{
|
|
|
|
|
const string body = "Success! You have properly configured your email notification settings";
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
SendEmail(settings, "Radarr - Test Notification", body);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error(ex, "Unable to send test email");
|
|
|
|
|
return new ValidationFailure("Server", "Unable to send test email");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SendEmail(EmailSettings settings, string subject, string body, bool htmlBody = false)
|
|
|
|
|
{
|
|
|
|
|
var email = new MimeMessage();
|
|
|
|
@ -129,52 +112,67 @@ namespace NzbDrone.Core.Notifications.Email
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Finished sending email. Subject: {0}", email.Subject);
|
|
|
|
|
_logger.Debug("Finished sending email. Subject: {0}", subject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Send(MimeMessage email, EmailSettings settings)
|
|
|
|
|
{
|
|
|
|
|
using (var client = new SmtpClient())
|
|
|
|
|
{
|
|
|
|
|
client.Timeout = 10000;
|
|
|
|
|
using var client = new SmtpClient();
|
|
|
|
|
client.Timeout = 10000;
|
|
|
|
|
|
|
|
|
|
var serverOption = SecureSocketOptions.Auto;
|
|
|
|
|
var serverOption = SecureSocketOptions.Auto;
|
|
|
|
|
|
|
|
|
|
if (settings.RequireEncryption)
|
|
|
|
|
if (settings.RequireEncryption)
|
|
|
|
|
{
|
|
|
|
|
if (settings.Port == 465)
|
|
|
|
|
{
|
|
|
|
|
serverOption = SecureSocketOptions.SslOnConnect;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (settings.Port == 465)
|
|
|
|
|
{
|
|
|
|
|
serverOption = SecureSocketOptions.SslOnConnect;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
serverOption = SecureSocketOptions.StartTls;
|
|
|
|
|
}
|
|
|
|
|
serverOption = SecureSocketOptions.StartTls;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client.ServerCertificateValidationCallback = _certificateValidationService.ShouldByPassValidationError;
|
|
|
|
|
client.ServerCertificateValidationCallback = _certificateValidationService.ShouldByPassValidationError;
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Connecting to mail server");
|
|
|
|
|
_logger.Debug("Connecting to mail server");
|
|
|
|
|
|
|
|
|
|
client.Connect(settings.Server, settings.Port, serverOption);
|
|
|
|
|
client.Connect(settings.Server, settings.Port, serverOption);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(settings.Username))
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Authenticating to mail server");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(settings.Username))
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Authenticating to mail server");
|
|
|
|
|
|
|
|
|
|
client.Authenticate(settings.Username, settings.Password);
|
|
|
|
|
}
|
|
|
|
|
client.Authenticate(settings.Username, settings.Password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Sending to mail server");
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Sending to mail server");
|
|
|
|
|
client.Send(email);
|
|
|
|
|
|
|
|
|
|
client.Send(email);
|
|
|
|
|
_logger.Debug("Sent to mail server, disconnecting");
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Sent to mail server, disconnecting");
|
|
|
|
|
client.Disconnect(true);
|
|
|
|
|
|
|
|
|
|
client.Disconnect(true);
|
|
|
|
|
_logger.Debug("Disconnecting from mail server");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ValidationFailure Test(EmailSettings settings)
|
|
|
|
|
{
|
|
|
|
|
const string body = "Success! You have properly configured your email notification settings";
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Disconnecting from mail server");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
SendEmail(settings, "Radarr - Test Notification", body);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error(ex, "Unable to send test email");
|
|
|
|
|
return new ValidationFailure("Server", "Unable to send test email");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MailboxAddress ParseAddress(string type, string address)
|
|
|
|
|