Added the logo in the email notifications to use the application image #1459

pull/1510/head
Jamie.Rees 7 years ago
parent 3cc45b3022
commit a77e518315

@ -11,36 +11,29 @@ namespace Ombi.Notifications.Templates
get
{
#if DEBUG
return Path.Combine(Directory.GetCurrentDirectory(), "bin","Debug", "netcoreapp1.1","Templates", "BasicTemplate.html");
return Path.Combine(Directory.GetCurrentDirectory(), "bin", "Debug", "netcoreapp1.1", "Templates", "BasicTemplate.html");
#else
return Path.Combine(Directory.GetCurrentDirectory(), "Templates","BasicTemplate.html");
#endif
}
}
private const string SubjectKey = "{@SUBJECT}";
private const string BodyKey = "{@BODY}";
private const string ImgSrc = "{@IMGSRC}";
private const string DateKey = "{@DATENOW}";
private const string Logo = "{@DATENOW}";
public string LoadTemplate(string subject, string body, string img)
public string LoadTemplate(string subject, string body, string img, string logo)
{
try
{
var sb = new StringBuilder(File.ReadAllText(TemplateLocation));
sb.Replace(SubjectKey, subject);
sb.Replace(BodyKey, body);
sb.Replace(DateKey, DateTime.Now.ToString("f"));
sb.Replace(ImgSrc, img);
var sb = new StringBuilder(File.ReadAllText(TemplateLocation));
sb.Replace(SubjectKey, subject);
sb.Replace(BodyKey, body);
sb.Replace(DateKey, DateTime.Now.ToString("f"));
sb.Replace(ImgSrc, img);
sb.Replace(Logo, string.IsNullOrEmpty(logo) ? "http://i.imgur.com/qQsN78U.png" : logo);
return sb.ToString();
}
catch (Exception e)
{
return string.Empty;
}
return sb.ToString();
}
}
}

@ -2,7 +2,7 @@
{
public interface IEmailBasicTemplate
{
string LoadTemplate(string subject, string body, string img);
string LoadTemplate(string subject, string body, string img, string logo);
string TemplateLocation { get; }
}
}

@ -144,7 +144,7 @@
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;" width="100%">
<tr>
<td align="center">
<img src="http://i.imgur.com/qQsN78U.png" width="400px" text-align="center" />
<img src="{@LOGO}" width="400px" text-align="center" />
</td>
</tr>
<tr>

@ -7,6 +7,7 @@ using Ombi.Helpers;
using Ombi.Notifications.Interfaces;
using Ombi.Notifications.Models;
using Ombi.Notifications.Templates;
using Ombi.Settings.Settings.Models;
using Ombi.Settings.Settings.Models.Notifications;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
@ -16,11 +17,13 @@ namespace Ombi.Notifications.Agents
{
public class EmailNotification : BaseNotification<EmailNotificationSettings>, IEmailNotification
{
public EmailNotification(ISettingsService<EmailNotificationSettings> settings, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, IEmailProvider prov) : base(settings, r, m, t)
public EmailNotification(ISettingsService<EmailNotificationSettings> settings, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, IEmailProvider prov, ISettingsService<CustomizationSettings> c) : base(settings, r, m, t)
{
EmailProvider = prov;
CustomizationSettings = c;
}
private IEmailProvider EmailProvider { get; }
private ISettingsService<CustomizationSettings> CustomizationSettings { get; }
public override string NotificationName => nameof(EmailNotification);
protected override bool ValidateConfiguration(EmailNotificationSettings settings)
@ -47,9 +50,11 @@ namespace Ombi.Notifications.Agents
private async Task<NotificationMessage> LoadTemplate(NotificationType type, NotificationOptions model, EmailNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Email, type, model);
var customization = await CustomizationSettings.GetSettingsAsync();
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(parsed.Subject, parsed.Message,parsed.Image);
var html = email.LoadTemplate(parsed.Subject, parsed.Message,parsed.Image, customization.Logo);
var message = new NotificationMessage
@ -108,9 +113,11 @@ namespace Ombi.Notifications.Agents
title = TvRequest.ParentRequest.Title;
img = TvRequest.ParentRequest.PosterPath;
}
var customization = await CustomizationSettings.GetSettingsAsync();
var html = email.LoadTemplate(
"Ombi: A request could not be added.",
$"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying", img);
$"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying", img, customization.Logo);
var message = new NotificationMessage
{
@ -173,9 +180,10 @@ namespace Ombi.Notifications.Agents
protected override async Task Test(NotificationOptions model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var customization = await CustomizationSettings.GetSettingsAsync();
var html = email.LoadTemplate(
"Test Message",
"This is just a test! Success!", "");
"This is just a test! Success!", "", customization.Logo);
var message = new NotificationMessage
{
Message = html,

Loading…
Cancel
Save