mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
Notifications can be tested
Notification ImplementationType was added for showing in UI (Humanized/Title cased of Implementation)
This commit is contained in:
parent
1f4cf0034e
commit
8cac7ed1cd
34 changed files with 418 additions and 328 deletions
|
@ -5,9 +5,9 @@ namespace NzbDrone.Core.Notifications.Email
|
|||
{
|
||||
public class Email : NotificationBase<EmailSettings>
|
||||
{
|
||||
private readonly EmailProvider _smtpProvider;
|
||||
private readonly IEmailService _smtpProvider;
|
||||
|
||||
public Email(EmailProvider smtpProvider)
|
||||
public Email(IEmailService smtpProvider)
|
||||
{
|
||||
_smtpProvider = smtpProvider;
|
||||
}
|
||||
|
@ -17,6 +17,11 @@ namespace NzbDrone.Core.Notifications.Email
|
|||
get { return "Email"; }
|
||||
}
|
||||
|
||||
public override string ImplementationName
|
||||
{
|
||||
get { return "Email"; }
|
||||
}
|
||||
|
||||
public override void OnGrab(string message)
|
||||
{
|
||||
const string subject = "NzbDrone [TV] - Grabbed";
|
||||
|
|
|
@ -2,19 +2,26 @@
|
|||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using Omu.ValueInjecter;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Email
|
||||
{
|
||||
public class EmailProvider
|
||||
public interface IEmailService
|
||||
{
|
||||
void SendEmail(EmailSettings settings, string subject, string body, bool htmlBody = false);
|
||||
}
|
||||
|
||||
public class EmailService : IEmailService, IExecute<TestEmailCommand>
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public EmailProvider(Logger logger)
|
||||
public EmailService(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public virtual void SendEmail(EmailSettings settings, string subject, string body, bool htmlBody = false)
|
||||
public void SendEmail(EmailSettings settings, string subject, string body, bool htmlBody = false)
|
||||
{
|
||||
var email = new MailMessage();
|
||||
email.From = new MailAddress(settings.From);
|
||||
|
@ -32,7 +39,7 @@ namespace NzbDrone.Core.Notifications.Email
|
|||
|
||||
try
|
||||
{
|
||||
Send(email, settings.Server, settings.Port, settings.UseSsl, credentials);
|
||||
Send(email, settings.Server, settings.Port, settings.Ssl, credentials);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
|
@ -41,7 +48,7 @@ namespace NzbDrone.Core.Notifications.Email
|
|||
}
|
||||
}
|
||||
|
||||
public virtual void Send(MailMessage email, string server, int port, bool ssl, NetworkCredential credentials)
|
||||
private void Send(MailMessage email, string server, int port, bool ssl, NetworkCredential credentials)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -60,5 +67,15 @@ namespace NzbDrone.Core.Notifications.Email
|
|||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(TestEmailCommand message)
|
||||
{
|
||||
var settings = new EmailSettings();
|
||||
settings.InjectFrom(message);
|
||||
|
||||
var body = "Success! You have properly configured your email notification settings";
|
||||
|
||||
SendEmail(settings, "NzbDrone - Test Notification", body);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,16 +11,16 @@ namespace NzbDrone.Core.Notifications.Email
|
|||
[FieldDefinition(1, Label = "Port")]
|
||||
public Int32 Port { get; set; }
|
||||
|
||||
[FieldDefinition(2, Label = "Use SSL", HelpText = "Does your Email server use SSL?")]
|
||||
public Boolean UseSsl { get; set; }
|
||||
[FieldDefinition(2, Label = "SSL", Type = FieldType.Checkbox)]
|
||||
public Boolean Ssl { get; set; }
|
||||
|
||||
[FieldDefinition(3, Label = "Username")]
|
||||
public String Username { get; set; }
|
||||
|
||||
[FieldDefinition(4, Label = "Password")]
|
||||
[FieldDefinition(4, Label = "Password", Type = FieldType.Password)]
|
||||
public String Password { get; set; }
|
||||
|
||||
[FieldDefinition(5, Label = "Sender Address")]
|
||||
[FieldDefinition(5, Label = "From Address")]
|
||||
public String From { get; set; }
|
||||
|
||||
[FieldDefinition(6, Label = "Recipient Address")]
|
||||
|
|
15
NzbDrone.Core/Notifications/Email/TestEmailCommand.cs
Normal file
15
NzbDrone.Core/Notifications/Email/TestEmailCommand.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using NzbDrone.Common.Messaging;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Email
|
||||
{
|
||||
public class TestEmailCommand : ICommand
|
||||
{
|
||||
public string Server { get; set; }
|
||||
public int Port { get; set; }
|
||||
public bool Ssl { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string From { get; set; }
|
||||
public string To { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue