Give correct feedback when testing email notifications #1513

pull/1520/head
Jamie.Rees 7 years ago
parent 3ca1e97855
commit 2499b0e370

@ -72,7 +72,7 @@ export class EmailNotificationComponent implements OnInit {
} }
this.testerService.emailTest(form.value).subscribe(x => { this.testerService.emailTest(form.value).subscribe(x => {
if (x) { if (x === true) {
this.notificationService.success("Sent", "Successfully sent an email message, please check your inbox"); this.notificationService.success("Sent", "Successfully sent an email message, please check your inbox");
} else { } else {
this.notificationService.success("Error", "There was an error when sending the Email message, please check your settings."); this.notificationService.success("Error", "There was an error when sending the Email message, please check your settings.");

@ -12,8 +12,10 @@ using Ombi.Attributes;
using Ombi.Core.Notifications; using Ombi.Core.Notifications;
using Ombi.Core.Settings.Models.External; using Ombi.Core.Settings.Models.External;
using Ombi.Helpers; using Ombi.Helpers;
using Ombi.Notifications;
using Ombi.Notifications.Agents; using Ombi.Notifications.Agents;
using Ombi.Notifications.Models; using Ombi.Notifications.Models;
using Ombi.Notifications.Templates;
using Ombi.Settings.Settings.Models.External; using Ombi.Settings.Settings.Models.External;
using Ombi.Settings.Settings.Models.Notifications; using Ombi.Settings.Settings.Models.Notifications;
@ -44,7 +46,7 @@ namespace Ombi.Controllers.External
/// <param name="log">The logger.</param> /// <param name="log">The logger.</param>
public TesterController(INotificationService service, IDiscordNotification notification, IEmailNotification emailN, public TesterController(INotificationService service, IDiscordNotification notification, IEmailNotification emailN,
IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm, IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm,
IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger<TesterController> log) IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger<TesterController> log, IEmailProvider provider)
{ {
Service = service; Service = service;
DiscordNotification = notification; DiscordNotification = notification;
@ -58,6 +60,7 @@ namespace Ombi.Controllers.External
EmbyApi = emby; EmbyApi = emby;
SonarrApi = sonarr; SonarrApi = sonarr;
Log = log; Log = log;
EmailProvider = provider;
} }
private INotificationService Service { get; } private INotificationService Service { get; }
@ -72,6 +75,7 @@ namespace Ombi.Controllers.External
private IEmbyApi EmbyApi { get; } private IEmbyApi EmbyApi { get; }
private ISonarrApi SonarrApi { get; } private ISonarrApi SonarrApi { get; }
private ILogger<TesterController> Log { get; } private ILogger<TesterController> Log { get; }
private IEmailProvider EmailProvider { get; }
/// <summary> /// <summary>
@ -156,15 +160,25 @@ namespace Ombi.Controllers.External
/// <param name="settings">The settings.</param> /// <param name="settings">The settings.</param>
/// <returns></returns> /// <returns></returns>
[HttpPost("email")] [HttpPost("email")]
public bool Email([FromBody] EmailNotificationSettings settings) public async Task<bool> Email([FromBody] EmailNotificationSettings settings)
{ {
settings.Enabled = true; try
var notificationModel = new NotificationOptions {
var message = new NotificationMessage
{
Message = "This is just a test! Success!",
Subject = $"Ombi: Test",
To = settings.AdminEmail,
};
message.Other.Add("PlainTextBody", "This is just a test! Success!");
await EmailProvider.SendAdHoc(message, settings);
}
catch (Exception e)
{ {
NotificationType = NotificationType.Test, Log.LogWarning(e, "Exception when testing Email Notifications");
RequestId = -1 return false;
}; }
EmailNotification.NotifyAsync(notificationModel, settings);
return true; return true;
} }

Loading…
Cancel
Save