From 16823e27398824401aa81584a14d74178c614ebc Mon Sep 17 00:00:00 2001 From: dhruvb14 Date: Tue, 31 Jan 2017 22:03:57 -0500 Subject: [PATCH 1/4] Begin Implementing Mass Email Section --- Ombi.Services/Interfaces/IMassEmail.cs | 9 +++ Ombi.Services/Interfaces/IRecentlyAdded.cs | 2 +- Ombi.Services/Jobs/RecentlyAdded.cs | 10 ++- Ombi.Services/Ombi.Services.csproj | 1 + Ombi.UI/Modules/Admin/AdminModule.cs | 41 ++++++++++-- Ombi.UI/Views/Admin/NewsletterSettings.cshtml | 65 ++++++++++++++++--- 6 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 Ombi.Services/Interfaces/IMassEmail.cs diff --git a/Ombi.Services/Interfaces/IMassEmail.cs b/Ombi.Services/Interfaces/IMassEmail.cs new file mode 100644 index 000000000..f3433c5f0 --- /dev/null +++ b/Ombi.Services/Interfaces/IMassEmail.cs @@ -0,0 +1,9 @@ +using Quartz; + +namespace Ombi.Services.Jobs +{ + public interface IMassEmail + { + void MassEmailAdminTest(); + } +} \ No newline at end of file diff --git a/Ombi.Services/Interfaces/IRecentlyAdded.cs b/Ombi.Services/Interfaces/IRecentlyAdded.cs index 09a7220f5..c18ca8e27 100644 --- a/Ombi.Services/Interfaces/IRecentlyAdded.cs +++ b/Ombi.Services/Interfaces/IRecentlyAdded.cs @@ -5,7 +5,7 @@ namespace Ombi.Services.Jobs public interface IRecentlyAdded { void Execute(IJobExecutionContext context); - void Test(); + void RecentlyAddedAdminTest(); void Start(); } } \ No newline at end of file diff --git a/Ombi.Services/Jobs/RecentlyAdded.cs b/Ombi.Services/Jobs/RecentlyAdded.cs index 563dd35a5..ece148398 100644 --- a/Ombi.Services/Jobs/RecentlyAdded.cs +++ b/Ombi.Services/Jobs/RecentlyAdded.cs @@ -48,7 +48,7 @@ using Quartz; namespace Ombi.Services.Jobs { - public class RecentlyAdded : HtmlTemplateGenerator, IJob, IRecentlyAdded + public class RecentlyAdded : HtmlTemplateGenerator, IJob, IRecentlyAdded, IMassEmail { public RecentlyAdded(IPlexApi api, ISettingsService plexSettings, ISettingsService email, IJobRecord rec, @@ -105,7 +105,13 @@ namespace Ombi.Services.Jobs Start(); } - public void Test() + public void RecentlyAddedAdminTest() + { + Log.Debug("Starting Recently Added Newsletter Test"); + var settings = NewsletterSettings.GetSettings(); + Start(settings, true); + } + public void MassEmailAdminTest() { Log.Debug("Starting Test Newsletter"); var settings = NewsletterSettings.GetSettings(); diff --git a/Ombi.Services/Ombi.Services.csproj b/Ombi.Services/Ombi.Services.csproj index 1735094dd..0e47b3669 100644 --- a/Ombi.Services/Ombi.Services.csproj +++ b/Ombi.Services/Ombi.Services.csproj @@ -87,6 +87,7 @@ + diff --git a/Ombi.UI/Modules/Admin/AdminModule.cs b/Ombi.UI/Modules/Admin/AdminModule.cs index a83ff8bd1..005646165 100644 --- a/Ombi.UI/Modules/Admin/AdminModule.cs +++ b/Ombi.UI/Modules/Admin/AdminModule.cs @@ -92,6 +92,7 @@ namespace Ombi.UI.Modules.Admin private IJobRecord JobRecorder { get; } private IAnalytics Analytics { get; } private IRecentlyAdded RecentlyAdded { get; } + private IMassEmail MassEmail { get; } private ISettingsService NotifySettings { get; } private ISettingsService DiscordSettings { get; } private IDiscordApi DiscordApi { get; } @@ -222,6 +223,9 @@ namespace Ombi.UI.Modules.Admin Get["/newsletter", true] = async (x, ct) => await Newsletter(); Post["/newsletter", true] = async (x, ct) => await SaveNewsletter(); + Post["/testnewsletteradminemail"] = x => TestNewsletterAdminEmail(); + Post["/testmassadminemail"] = x => TestMassAdminEmail(); + Post["/sendmassemail"] = x => SendMassEmail(); Post["/createapikey"] = x => CreateApiKey(); @@ -246,7 +250,6 @@ namespace Ombi.UI.Modules.Admin Get["/notificationsettings", true] = async (x, ct) => await NotificationSettings(); Post["/notificationsettings"] = x => SaveNotificationSettings(); - Post["/recentlyAddedTest"] = x => RecentlyAddedTest(); } private async Task Authentication() @@ -1229,13 +1232,41 @@ namespace Ombi.UI.Modules.Admin var model = this.Bind(); return View["NotificationSettings", model]; } - - private Response RecentlyAddedTest() + + private Response TestNewsletterAdminEmail() { try { - Log.Debug("Clicked TEST"); - RecentlyAdded.Test(); + Log.Debug("Clicked Admin Newsletter Email Test"); + RecentlyAdded.RecentlyAddedAdminTest(); + return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" }); + } + catch (Exception e) + { + Log.Error(e); + return Response.AsJson(new JsonResponseModel { Result = false, Message = e.Message }); + } + } + private Response TestMassAdminEmail() + { + try + { + Log.Debug("Clicked Admin Mass Email Test"); + RecentlyAdded.RecentlyAddedAdminTest(); + return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" }); + } + catch (Exception e) + { + Log.Error(e); + return Response.AsJson(new JsonResponseModel { Result = false, Message = e.Message }); + } + } + private Response SendMassEmail() + { + try + { + Log.Debug("Clicked Send Mass Email"); + RecentlyAdded.RecentlyAddedAdminTest(); return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" }); } catch (Exception e) diff --git a/Ombi.UI/Views/Admin/NewsletterSettings.cshtml b/Ombi.UI/Views/Admin/NewsletterSettings.cshtml index 898a7a761..0a1e07852 100644 --- a/Ombi.UI/Views/Admin/NewsletterSettings.cshtml +++ b/Ombi.UI/Views/Admin/NewsletterSettings.cshtml @@ -28,17 +28,17 @@
-
+
- You can add multiple email addresses by using the ; delimiter -
+ You can add multiple email addresses by using the ; delimiter +
- +
@@ -46,7 +46,7 @@
- +
@@ -54,6 +54,23 @@ +
+
+ Mass Email +
+ + + + Supports HTML + +
+
+
+ +
+
+
+
@@ -90,8 +107,8 @@ $('#recentlyAddedBtn').click(function (e) { e.preventDefault(); var base = '@Html.GetBaseUrl()'; - var url = createBaseUrl(base, '/admin/recentlyAddedTest'); - $('#spinner').attr("class", "fa fa-spinner fa-spin"); + var url = createBaseUrl(base, '/admin/testnewsletteradminemail'); + $('#testEmailSpinner').attr("class", "fa fa-spinner fa-spin"); $.ajax({ type: "post", url: url, @@ -99,17 +116,45 @@ success: function (response) { if (response) { generateNotify(response.message, "success"); - $('#spinner').attr("class", "fa fa-check"); + $('#testEmailSpinner').attr("class", "fa fa-check"); } else { generateNotify(response.message, "danger"); - $('#spinner').attr("class", "fa fa-times"); + $('#testEmailSpinner').attr("class", "fa fa-times"); } }, error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); - $('#spinner').attr("class", "fa fa-times"); + $('#testEmailSpinner').attr("class", "fa fa-times"); + } + }); + }); + + $('#sendMassEmailBtn').click(function (e) { + e.preventDefault(); + var base = '@Html.GetBaseUrl()'; + var url = createBaseUrl(base, '/admin/testmassadminemail'); + $('#sendMassEmailSpinner').attr("class", "fa fa-spinner fa-spin"); + $.ajax({ + type: "post", + url: url, + data: $("#massEmailBody").val(), + dataType: "json", + success: function (response) { + if (response) { + generateNotify(response.message, "success"); + $('#sendMassEmailSpinner').attr("class", "fa fa-check"); + } else { + + generateNotify(response.message, "danger"); + $('#sendMassEmailSpinner').attr("class", "fa fa-times"); + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + $('#sendMassEmailSpinner').attr("class", "fa fa-times"); } }); }); From 8f3c4ca1b2cf3bcf18fb3bdfebc6b67d3ce13adf Mon Sep 17 00:00:00 2001 From: dhruvb14 Date: Tue, 31 Jan 2017 22:54:58 -0500 Subject: [PATCH 2/4] Does not compile, need to get data from UI into nancy somehow and figure out why IMassEmail is not initializing --- Ombi.Services/Interfaces/IMassEmail.cs | 3 +- Ombi.Services/Jobs/RecentlyAdded.cs | 9 +- .../Jobs/Templates/MassEmailTemplate.cs | 58 ++++++ .../Jobs/Templates/MassEmailTemplate.html | 181 ++++++++++++++++++ Ombi.Services/Ombi.Services.csproj | 4 + Ombi.UI/Modules/Admin/AdminModule.cs | 5 +- Ombi.UI/Views/Admin/NewsletterSettings.cshtml | 2 +- 7 files changed, 255 insertions(+), 7 deletions(-) create mode 100644 Ombi.Services/Jobs/Templates/MassEmailTemplate.cs create mode 100644 Ombi.Services/Jobs/Templates/MassEmailTemplate.html diff --git a/Ombi.Services/Interfaces/IMassEmail.cs b/Ombi.Services/Interfaces/IMassEmail.cs index f3433c5f0..c7b88cad9 100644 --- a/Ombi.Services/Interfaces/IMassEmail.cs +++ b/Ombi.Services/Interfaces/IMassEmail.cs @@ -4,6 +4,7 @@ namespace Ombi.Services.Jobs { public interface IMassEmail { - void MassEmailAdminTest(); + void Execute(IJobExecutionContext context); + void MassEmailAdminTest(string html); } } \ No newline at end of file diff --git a/Ombi.Services/Jobs/RecentlyAdded.cs b/Ombi.Services/Jobs/RecentlyAdded.cs index ece148398..937eac8ab 100644 --- a/Ombi.Services/Jobs/RecentlyAdded.cs +++ b/Ombi.Services/Jobs/RecentlyAdded.cs @@ -111,11 +111,14 @@ namespace Ombi.Services.Jobs var settings = NewsletterSettings.GetSettings(); Start(settings, true); } - public void MassEmailAdminTest() + public void MassEmailAdminTest(string html) { - Log.Debug("Starting Test Newsletter"); + Log.Debug("Starting Mass Email Test"); var settings = NewsletterSettings.GetSettings(); - Start(settings, true); + var plexSettings = PlexSettings.GetSettings(); + var template = new MassEmailTemplate(); + var body = template.LoadTemplate(html); + Send(settings, body, plexSettings, true); } private void Start(NewletterSettings newletterSettings, bool testEmail = false) diff --git a/Ombi.Services/Jobs/Templates/MassEmailTemplate.cs b/Ombi.Services/Jobs/Templates/MassEmailTemplate.cs new file mode 100644 index 000000000..ea73c027d --- /dev/null +++ b/Ombi.Services/Jobs/Templates/MassEmailTemplate.cs @@ -0,0 +1,58 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: RecentlyAddedTemplate.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion + +using System; +using System.IO; +using System.Text; +using System.Windows.Forms; +using NLog; + +namespace Ombi.Services.Jobs.Templates +{ + public class MassEmailTemplate + { + public string TemplateLocation => Path.Combine(Path.GetDirectoryName(Application.ExecutablePath) ?? string.Empty, "Jobs", "Templates", "MassEmailTemplate.html"); + private static readonly Logger Log = LogManager.GetCurrentClassLogger(); + + private const string RecentlyAddedKey = "{@MASSEMAIL}"; + + public string LoadTemplate(string html) + { + try + { + var sb = new StringBuilder(File.ReadAllText(TemplateLocation)); + sb.Replace(RecentlyAddedKey, html); + return sb.ToString(); + } + catch (Exception e) + { + Log.Error(e); + return string.Empty; + } + } + } +} \ No newline at end of file diff --git a/Ombi.Services/Jobs/Templates/MassEmailTemplate.html b/Ombi.Services/Jobs/Templates/MassEmailTemplate.html new file mode 100644 index 000000000..4fdd04524 --- /dev/null +++ b/Ombi.Services/Jobs/Templates/MassEmailTemplate.html @@ -0,0 +1,181 @@ + + + + + + Ombi + + + + + + + + + +
  +
+ + + + + + + + + + + +
+ + + + + + + +
+ +
+ {@MASSEMAIL} +
+
+ + + + + + +
+
 
+ + \ No newline at end of file diff --git a/Ombi.Services/Ombi.Services.csproj b/Ombi.Services/Ombi.Services.csproj index 0e47b3669..a37279f7d 100644 --- a/Ombi.Services/Ombi.Services.csproj +++ b/Ombi.Services/Ombi.Services.csproj @@ -108,6 +108,7 @@ + @@ -181,6 +182,9 @@
+ + PreserveNewest + PreserveNewest diff --git a/Ombi.UI/Modules/Admin/AdminModule.cs b/Ombi.UI/Modules/Admin/AdminModule.cs index 005646165..181cc1d1b 100644 --- a/Ombi.UI/Modules/Admin/AdminModule.cs +++ b/Ombi.UI/Modules/Admin/AdminModule.cs @@ -124,7 +124,7 @@ namespace Ombi.UI.Modules.Admin ICacheProvider cache, ISettingsService slackSettings, ISlackApi slackApi, ISettingsService lp, ISettingsService scheduler, IJobRecord rec, IAnalytics analytics, - ISettingsService notifyService, IRecentlyAdded recentlyAdded, + ISettingsService notifyService, IRecentlyAdded recentlyAdded, IMassEmail massEmail, ISettingsService watcherSettings , ISettingsService discord, IDiscordApi discordapi, ISettingsService settings, IRadarrApi radarrApi, @@ -159,6 +159,7 @@ namespace Ombi.UI.Modules.Admin Analytics = analytics; NotifySettings = notifyService; RecentlyAdded = recentlyAdded; + MassEmail = massEmail; WatcherSettings = watcherSettings; DiscordSettings = discord; DiscordApi = discordapi; @@ -1252,7 +1253,7 @@ namespace Ombi.UI.Modules.Admin try { Log.Debug("Clicked Admin Mass Email Test"); - RecentlyAdded.RecentlyAddedAdminTest(); + MassEmail.MassEmailAdminTest("Dhruv's Test Email"); return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" }); } catch (Exception e) diff --git a/Ombi.UI/Views/Admin/NewsletterSettings.cshtml b/Ombi.UI/Views/Admin/NewsletterSettings.cshtml index 0a1e07852..02958cb33 100644 --- a/Ombi.UI/Views/Admin/NewsletterSettings.cshtml +++ b/Ombi.UI/Views/Admin/NewsletterSettings.cshtml @@ -66,7 +66,7 @@
- +
From 7a2a0573467b695b351953af521ceac0eec13eb5 Mon Sep 17 00:00:00 2001 From: dhruvb14 Date: Wed, 1 Feb 2017 10:06:50 -0500 Subject: [PATCH 3/4] @tidusjar pointed out runtime error!! --- Ombi.UI/NinjectModules/ServicesModule.cs | 1 + Ombi.UI/Views/Admin/NewsletterSettings.cshtml | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Ombi.UI/NinjectModules/ServicesModule.cs b/Ombi.UI/NinjectModules/ServicesModule.cs index 95dfcf433..95fbe4ba5 100644 --- a/Ombi.UI/NinjectModules/ServicesModule.cs +++ b/Ombi.UI/NinjectModules/ServicesModule.cs @@ -49,6 +49,7 @@ namespace Ombi.UI.NinjectModules Bind().To(); Bind().To(); Bind().To(); + Bind().To(); Bind().To(); Bind().To(); Bind().To(); diff --git a/Ombi.UI/Views/Admin/NewsletterSettings.cshtml b/Ombi.UI/Views/Admin/NewsletterSettings.cshtml index 02958cb33..3d02e89d4 100644 --- a/Ombi.UI/Views/Admin/NewsletterSettings.cshtml +++ b/Ombi.UI/Views/Admin/NewsletterSettings.cshtml @@ -64,6 +64,11 @@ Supports HTML +
+
+ +
+
@@ -116,26 +121,26 @@ success: function (response) { if (response) { generateNotify(response.message, "success"); - $('#testEmailSpinner').attr("class", "fa fa-check"); + $('#testSendMassEmailSpinner').attr("class", "fa fa-check"); } else { generateNotify(response.message, "danger"); - $('#testEmailSpinner').attr("class", "fa fa-times"); + $('#testSendMassEmailSpinner').attr("class", "fa fa-times"); } }, error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); - $('#testEmailSpinner').attr("class", "fa fa-times"); + $('#testSendMassEmailSpinner').attr("class", "fa fa-times"); } }); }); - $('#sendMassEmailBtn').click(function (e) { + $('#testSendMassEmailBtn').click(function (e) { e.preventDefault(); var base = '@Html.GetBaseUrl()'; var url = createBaseUrl(base, '/admin/testmassadminemail'); - $('#sendMassEmailSpinner').attr("class", "fa fa-spinner fa-spin"); + $('#testSendMassEmailSpinner').attr("class", "fa fa-spinner fa-spin"); $.ajax({ type: "post", url: url, @@ -144,17 +149,17 @@ success: function (response) { if (response) { generateNotify(response.message, "success"); - $('#sendMassEmailSpinner').attr("class", "fa fa-check"); + $('#testSendMassEmailSpinner').attr("class", "fa fa-check"); } else { generateNotify(response.message, "danger"); - $('#sendMassEmailSpinner').attr("class", "fa fa-times"); + $('#testSendMassEmailSpinner').attr("class", "fa fa-times"); } }, error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); - $('#sendMassEmailSpinner').attr("class", "fa fa-times"); + $('#testSendMassEmailSpinner').attr("class", "fa fa-times"); } }); }); From ca9469407695bea006e740c9558b6ebcaebf4de7 Mon Sep 17 00:00:00 2001 From: dhruvb14 Date: Wed, 1 Feb 2017 23:49:30 -0500 Subject: [PATCH 4/4] finish implementing mass email feature --- Ombi.Core/Ombi.Core.csproj | 1 + Ombi.Core/SettingModels/MassEmailSettings.cs | 35 +++++ Ombi.Services/Interfaces/IMassEmail.cs | 4 +- Ombi.Services/Jobs/RecentlyAdded.cs | 17 ++- .../Jobs/Templates/MassEmailTemplate.html | 2 +- Ombi.UI/Modules/Admin/AdminModule.cs | 25 +++- Ombi.UI/Views/Admin/NewsletterSettings.cshtml | 134 ++++++++++++------ 7 files changed, 162 insertions(+), 56 deletions(-) create mode 100644 Ombi.Core/SettingModels/MassEmailSettings.cs diff --git a/Ombi.Core/Ombi.Core.csproj b/Ombi.Core/Ombi.Core.csproj index 9866e6fb0..f6562c2fc 100644 --- a/Ombi.Core/Ombi.Core.csproj +++ b/Ombi.Core/Ombi.Core.csproj @@ -124,6 +124,7 @@ + diff --git a/Ombi.Core/SettingModels/MassEmailSettings.cs b/Ombi.Core/SettingModels/MassEmailSettings.cs new file mode 100644 index 000000000..0be28a92d --- /dev/null +++ b/Ombi.Core/SettingModels/MassEmailSettings.cs @@ -0,0 +1,35 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: EmailNotificationSettings.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion +namespace Ombi.Core.SettingModels +{ + public sealed class MassEmailSettings : NotificationSettings + { + public string Users { get; set; } + public string Subject { get; set; } + public string Body { get; set; } + } +} \ No newline at end of file diff --git a/Ombi.Services/Interfaces/IMassEmail.cs b/Ombi.Services/Interfaces/IMassEmail.cs index c7b88cad9..9751cc870 100644 --- a/Ombi.Services/Interfaces/IMassEmail.cs +++ b/Ombi.Services/Interfaces/IMassEmail.cs @@ -5,6 +5,8 @@ namespace Ombi.Services.Jobs public interface IMassEmail { void Execute(IJobExecutionContext context); - void MassEmailAdminTest(string html); + void MassEmailAdminTest(string html, string subject); + void SendMassEmail(string html, string subject); + } } \ No newline at end of file diff --git a/Ombi.Services/Jobs/RecentlyAdded.cs b/Ombi.Services/Jobs/RecentlyAdded.cs index 937eac8ab..9ee52f231 100644 --- a/Ombi.Services/Jobs/RecentlyAdded.cs +++ b/Ombi.Services/Jobs/RecentlyAdded.cs @@ -111,14 +111,23 @@ namespace Ombi.Services.Jobs var settings = NewsletterSettings.GetSettings(); Start(settings, true); } - public void MassEmailAdminTest(string html) + public void MassEmailAdminTest(string html, string subject) { Log.Debug("Starting Mass Email Test"); var settings = NewsletterSettings.GetSettings(); var plexSettings = PlexSettings.GetSettings(); var template = new MassEmailTemplate(); var body = template.LoadTemplate(html); - Send(settings, body, plexSettings, true); + Send(settings, body, plexSettings, true, subject); + } + public void SendMassEmail(string html, string subject) + { + Log.Debug("Starting Mass Email Test"); + var settings = NewsletterSettings.GetSettings(); + var plexSettings = PlexSettings.GetSettings(); + var template = new MassEmailTemplate(); + var body = template.LoadTemplate(html); + Send(settings, body, plexSettings, false, subject); } private void Start(NewletterSettings newletterSettings, bool testEmail = false) @@ -448,7 +457,7 @@ namespace Ombi.Services.Jobs sb.Append("

"); } - private void Send(NewletterSettings newletterSettings, string html, PlexSettings plexSettings, bool testEmail = false) + private void Send(NewletterSettings newletterSettings, string html, PlexSettings plexSettings, bool testEmail = false, string subject = "New Content on Plex!") { Log.Debug("Entering Send"); var settings = EmailSettings.GetSettings(); @@ -463,7 +472,7 @@ namespace Ombi.Services.Jobs var message = new MimeMessage { Body = body.ToMessageBody(), - Subject = "New Content on Plex!", + Subject = subject }; Log.Debug("Created Plain/HTML MIME body"); diff --git a/Ombi.Services/Jobs/Templates/MassEmailTemplate.html b/Ombi.Services/Jobs/Templates/MassEmailTemplate.html index 4fdd04524..02214c6af 100644 --- a/Ombi.Services/Jobs/Templates/MassEmailTemplate.html +++ b/Ombi.Services/Jobs/Templates/MassEmailTemplate.html @@ -148,7 +148,7 @@ - + {@MASSEMAIL} diff --git a/Ombi.UI/Modules/Admin/AdminModule.cs b/Ombi.UI/Modules/Admin/AdminModule.cs index 181cc1d1b..a0b6216f7 100644 --- a/Ombi.UI/Modules/Admin/AdminModule.cs +++ b/Ombi.UI/Modules/Admin/AdminModule.cs @@ -1252,8 +1252,16 @@ namespace Ombi.UI.Modules.Admin { try { + var settings = this.Bind(); Log.Debug("Clicked Admin Mass Email Test"); - MassEmail.MassEmailAdminTest("Dhruv's Test Email"); + if (settings.Subject == null) { + return Response.AsJson(new JsonResponseModel { Result = false, Message = "Please Set a Subject" }); + } + if (settings.Body == null) + { + return Response.AsJson(new JsonResponseModel { Result = false, Message = "Please Set a Body" }); + } + MassEmail.MassEmailAdminTest(settings.Body.Replace("\n", "
"), settings.Subject); return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" }); } catch (Exception e) @@ -1266,9 +1274,18 @@ namespace Ombi.UI.Modules.Admin { try { - Log.Debug("Clicked Send Mass Email"); - RecentlyAdded.RecentlyAddedAdminTest(); - return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" }); + var settings = this.Bind(); + Log.Debug("Clicked Admin Mass Email Test"); + if (settings.Subject == null) + { + return Response.AsJson(new JsonResponseModel { Result = false, Message = "Please Set a Subject" }); + } + if (settings.Body == null) + { + return Response.AsJson(new JsonResponseModel { Result = false, Message = "Please Set a Body" }); + } + MassEmail.SendMassEmail(settings.Body.Replace("\n", "
"), settings.Subject); + return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to All users" }); } catch (Exception e) { diff --git a/Ombi.UI/Views/Admin/NewsletterSettings.cshtml b/Ombi.UI/Views/Admin/NewsletterSettings.cshtml index 3d02e89d4..2b9f52838 100644 --- a/Ombi.UI/Views/Admin/NewsletterSettings.cshtml +++ b/Ombi.UI/Views/Admin/NewsletterSettings.cshtml @@ -7,46 +7,48 @@
Newsletter Settings +
- -
-
+ +
+
- Note: This will require you to setup your email notifications -
- @if (Model.SendRecentlyAddedEmail) - { - - } - else - { - - } + Note: This will require you to setup your email notifications +
+ @if (Model.SendRecentlyAddedEmail) + { + + } + else + { + + } +
-
-
+
-
- - You can add multiple email addresses by using the ; delimiter -
- +
+ + You can add multiple email addresses by using the ; delimiter +
+ +
-
-
-
- +
+
+ +
-
-
-
-
-
- +
+
+
+
+ +
@@ -57,21 +59,32 @@
Mass Email -
- - - - Supports HTML - -
-
-
- +
+
+ Note: This will require you to setup your email notifications
-
-
-
- +
+ +
+ +
+
+
+ + + + Supports HTML + +
+
+
+ +
+
+
+
+ +
@@ -141,13 +154,14 @@ var base = '@Html.GetBaseUrl()'; var url = createBaseUrl(base, '/admin/testmassadminemail'); $('#testSendMassEmailSpinner').attr("class", "fa fa-spinner fa-spin"); + var data = { "Users": "", "Body": $("#massEmailBody").val(), "Subject": $("#massEmailSubject").val() }; $.ajax({ type: "post", url: url, - data: $("#massEmailBody").val(), + data: data, dataType: "json", success: function (response) { - if (response) { + if (response.result) { generateNotify(response.message, "success"); $('#testSendMassEmailSpinner').attr("class", "fa fa-check"); } else { @@ -163,6 +177,34 @@ } }); }); + $('#sendMassEmailBtn').click(function (e) { + e.preventDefault(); + var base = '@Html.GetBaseUrl()'; + var url = createBaseUrl(base, '/admin/sendmassemail'); + $('#sendMassEmailSpinner').attr("class", "fa fa-spinner fa-spin"); + var data = { "Users": "", "Body": $("#massEmailBody").val(), "Subject": $("#massEmailSubject").val() }; + $.ajax({ + type: "post", + url: url, + data: data, + dataType: "json", + success: function (response) { + if (response.result) { + generateNotify(response.message, "success"); + $('#sendMassEmailSpinner').attr("class", "fa fa-check"); + } else { + + generateNotify(response.message, "danger"); + $('#sendMassEmailSpinner').attr("class", "fa fa-times"); + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + $('#sendMassEmailSpinner').attr("class", "fa fa-times"); + } + }); + }); });