mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
Added the logo in the email notifications to use the application image #1459
This commit is contained in:
parent
3cc45b3022
commit
a77e518315
4 changed files with 25 additions and 24 deletions
|
@ -11,36 +11,29 @@ namespace Ombi.Notifications.Templates
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#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
|
#else
|
||||||
return Path.Combine(Directory.GetCurrentDirectory(), "Templates","BasicTemplate.html");
|
return Path.Combine(Directory.GetCurrentDirectory(), "Templates","BasicTemplate.html");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private const string SubjectKey = "{@SUBJECT}";
|
private const string SubjectKey = "{@SUBJECT}";
|
||||||
private const string BodyKey = "{@BODY}";
|
private const string BodyKey = "{@BODY}";
|
||||||
private const string ImgSrc = "{@IMGSRC}";
|
private const string ImgSrc = "{@IMGSRC}";
|
||||||
private const string DateKey = "{@DATENOW}";
|
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);
|
||||||
var sb = new StringBuilder(File.ReadAllText(TemplateLocation));
|
sb.Replace(BodyKey, body);
|
||||||
sb.Replace(SubjectKey, subject);
|
sb.Replace(DateKey, DateTime.Now.ToString("f"));
|
||||||
sb.Replace(BodyKey, body);
|
sb.Replace(ImgSrc, img);
|
||||||
sb.Replace(DateKey, DateTime.Now.ToString("f"));
|
sb.Replace(Logo, string.IsNullOrEmpty(logo) ? "http://i.imgur.com/qQsN78U.png" : logo);
|
||||||
sb.Replace(ImgSrc, img);
|
|
||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{
|
{
|
||||||
public interface IEmailBasicTemplate
|
public interface IEmailBasicTemplate
|
||||||
{
|
{
|
||||||
string LoadTemplate(string subject, string body, string img);
|
string LoadTemplate(string subject, string body, string img, string logo);
|
||||||
string TemplateLocation { get; }
|
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%">
|
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;" width="100%">
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center">
|
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -7,6 +7,7 @@ using Ombi.Helpers;
|
||||||
using Ombi.Notifications.Interfaces;
|
using Ombi.Notifications.Interfaces;
|
||||||
using Ombi.Notifications.Models;
|
using Ombi.Notifications.Models;
|
||||||
using Ombi.Notifications.Templates;
|
using Ombi.Notifications.Templates;
|
||||||
|
using Ombi.Settings.Settings.Models;
|
||||||
using Ombi.Settings.Settings.Models.Notifications;
|
using Ombi.Settings.Settings.Models.Notifications;
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Repository;
|
using Ombi.Store.Repository;
|
||||||
|
@ -16,11 +17,13 @@ namespace Ombi.Notifications.Agents
|
||||||
{
|
{
|
||||||
public class EmailNotification : BaseNotification<EmailNotificationSettings>, IEmailNotification
|
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;
|
EmailProvider = prov;
|
||||||
|
CustomizationSettings = c;
|
||||||
}
|
}
|
||||||
private IEmailProvider EmailProvider { get; }
|
private IEmailProvider EmailProvider { get; }
|
||||||
|
private ISettingsService<CustomizationSettings> CustomizationSettings { get; }
|
||||||
public override string NotificationName => nameof(EmailNotification);
|
public override string NotificationName => nameof(EmailNotification);
|
||||||
|
|
||||||
protected override bool ValidateConfiguration(EmailNotificationSettings settings)
|
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)
|
private async Task<NotificationMessage> LoadTemplate(NotificationType type, NotificationOptions model, EmailNotificationSettings settings)
|
||||||
{
|
{
|
||||||
var parsed = await LoadTemplate(NotificationAgent.Email, type, model);
|
var parsed = await LoadTemplate(NotificationAgent.Email, type, model);
|
||||||
|
|
||||||
|
var customization = await CustomizationSettings.GetSettingsAsync();
|
||||||
|
|
||||||
var email = new EmailBasicTemplate();
|
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
|
var message = new NotificationMessage
|
||||||
|
@ -108,9 +113,11 @@ namespace Ombi.Notifications.Agents
|
||||||
title = TvRequest.ParentRequest.Title;
|
title = TvRequest.ParentRequest.Title;
|
||||||
img = TvRequest.ParentRequest.PosterPath;
|
img = TvRequest.ParentRequest.PosterPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var customization = await CustomizationSettings.GetSettingsAsync();
|
||||||
var html = email.LoadTemplate(
|
var html = email.LoadTemplate(
|
||||||
"Ombi: A request could not be added.",
|
"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
|
var message = new NotificationMessage
|
||||||
{
|
{
|
||||||
|
@ -173,9 +180,10 @@ namespace Ombi.Notifications.Agents
|
||||||
protected override async Task Test(NotificationOptions model, EmailNotificationSettings settings)
|
protected override async Task Test(NotificationOptions model, EmailNotificationSettings settings)
|
||||||
{
|
{
|
||||||
var email = new EmailBasicTemplate();
|
var email = new EmailBasicTemplate();
|
||||||
|
var customization = await CustomizationSettings.GetSettingsAsync();
|
||||||
var html = email.LoadTemplate(
|
var html = email.LoadTemplate(
|
||||||
"Test Message",
|
"Test Message",
|
||||||
"This is just a test! Success!", "");
|
"This is just a test! Success!", "", customization.Logo);
|
||||||
var message = new NotificationMessage
|
var message = new NotificationMessage
|
||||||
{
|
{
|
||||||
Message = html,
|
Message = html,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue