mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 07:46:05 -07:00
finish implementing mass email feature
This commit is contained in:
parent
7a2a057346
commit
ca94694076
7 changed files with 162 additions and 56 deletions
|
@ -124,6 +124,7 @@
|
||||||
<Compile Include="SettingModels\AuthenticationSettings.cs" />
|
<Compile Include="SettingModels\AuthenticationSettings.cs" />
|
||||||
<Compile Include="SettingModels\DiscordNotificationSettings.cs" />
|
<Compile Include="SettingModels\DiscordNotificationSettings.cs" />
|
||||||
<Compile Include="SettingModels\EmbySettings.cs" />
|
<Compile Include="SettingModels\EmbySettings.cs" />
|
||||||
|
<Compile Include="SettingModels\MassEmailSettings.cs" />
|
||||||
<Compile Include="SettingModels\RadarrSettings.cs" />
|
<Compile Include="SettingModels\RadarrSettings.cs" />
|
||||||
<Compile Include="SettingModels\WatcherSettings.cs" />
|
<Compile Include="SettingModels\WatcherSettings.cs" />
|
||||||
<Compile Include="SettingModels\ExternalSettings.cs" />
|
<Compile Include="SettingModels\ExternalSettings.cs" />
|
||||||
|
|
35
Ombi.Core/SettingModels/MassEmailSettings.cs
Normal file
35
Ombi.Core/SettingModels/MassEmailSettings.cs
Normal file
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,8 @@ namespace Ombi.Services.Jobs
|
||||||
public interface IMassEmail
|
public interface IMassEmail
|
||||||
{
|
{
|
||||||
void Execute(IJobExecutionContext context);
|
void Execute(IJobExecutionContext context);
|
||||||
void MassEmailAdminTest(string html);
|
void MassEmailAdminTest(string html, string subject);
|
||||||
|
void SendMassEmail(string html, string subject);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -111,14 +111,23 @@ namespace Ombi.Services.Jobs
|
||||||
var settings = NewsletterSettings.GetSettings();
|
var settings = NewsletterSettings.GetSettings();
|
||||||
Start(settings, true);
|
Start(settings, true);
|
||||||
}
|
}
|
||||||
public void MassEmailAdminTest(string html)
|
public void MassEmailAdminTest(string html, string subject)
|
||||||
{
|
{
|
||||||
Log.Debug("Starting Mass Email Test");
|
Log.Debug("Starting Mass Email Test");
|
||||||
var settings = NewsletterSettings.GetSettings();
|
var settings = NewsletterSettings.GetSettings();
|
||||||
var plexSettings = PlexSettings.GetSettings();
|
var plexSettings = PlexSettings.GetSettings();
|
||||||
var template = new MassEmailTemplate();
|
var template = new MassEmailTemplate();
|
||||||
var body = template.LoadTemplate(html);
|
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)
|
private void Start(NewletterSettings newletterSettings, bool testEmail = false)
|
||||||
|
@ -448,7 +457,7 @@ namespace Ombi.Services.Jobs
|
||||||
sb.Append("</table><br /><br />");
|
sb.Append("</table><br /><br />");
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
Log.Debug("Entering Send");
|
||||||
var settings = EmailSettings.GetSettings();
|
var settings = EmailSettings.GetSettings();
|
||||||
|
@ -463,7 +472,7 @@ namespace Ombi.Services.Jobs
|
||||||
var message = new MimeMessage
|
var message = new MimeMessage
|
||||||
{
|
{
|
||||||
Body = body.ToMessageBody(),
|
Body = body.ToMessageBody(),
|
||||||
Subject = "New Content on Plex!",
|
Subject = subject
|
||||||
};
|
};
|
||||||
Log.Debug("Created Plain/HTML MIME body");
|
Log.Debug("Created Plain/HTML MIME body");
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center">
|
<td align="left">
|
||||||
{@MASSEMAIL}
|
{@MASSEMAIL}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -1252,8 +1252,16 @@ namespace Ombi.UI.Modules.Admin
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var settings = this.Bind<MassEmailSettings>();
|
||||||
Log.Debug("Clicked Admin Mass Email Test");
|
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", "<br/>"), settings.Subject);
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" });
|
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" });
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -1266,9 +1274,18 @@ namespace Ombi.UI.Modules.Admin
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Log.Debug("Clicked Send Mass Email");
|
var settings = this.Bind<MassEmailSettings>();
|
||||||
RecentlyAdded.RecentlyAddedAdminTest();
|
Log.Debug("Clicked Admin Mass Email Test");
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" });
|
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", "<br/>"), settings.Subject);
|
||||||
|
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to All users" });
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
<form class="form-horizontal" method="POST" id="mainForm">
|
<form class="form-horizontal" method="POST" id="mainForm">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Newsletter Settings</legend>
|
<legend>Newsletter Settings</legend>
|
||||||
|
<div style="padding:10px">
|
||||||
|
|
||||||
<!-- Email Nofication Section -->
|
<!-- Email Nofication Section -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -49,6 +50,7 @@
|
||||||
<button type="submit" id="save" class="btn btn-primary-outline">Save</button>
|
<button type="submit" id="save" class="btn btn-primary-outline">Save</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<!-- Email Nofication Section -->
|
<!-- Email Nofication Section -->
|
||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -57,8 +59,18 @@
|
||||||
<form id="massemail" class="form-horizontal">
|
<form id="massemail" class="form-horizontal">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Mass Email</legend>
|
<legend>Mass Email</legend>
|
||||||
|
<div style="padding:10px">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="massEmailBody" class="control-label">Send mass email to all users who recieve newsletter</label>
|
<small>Note: This will require you to setup your email notifications</small>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="massEmailSubject" class="control-label">Subject</label>
|
||||||
|
<div>
|
||||||
|
<input type="text" class="form-control form-control-custom " placeholder="A Message from Plex Admin" id="massEmailSubject" name="massEmailSubject" value="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="massEmailBody" class="control-label">Body</label>
|
||||||
|
|
||||||
<textarea id="massEmailBody" class="form-control" rows="5"></textarea>
|
<textarea id="massEmailBody" class="form-control" rows="5"></textarea>
|
||||||
<small>Supports HTML</small>
|
<small>Supports HTML</small>
|
||||||
|
@ -71,7 +83,8 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div>
|
<div>
|
||||||
<button id="sendMassEmailBtn" class="btn btn-primary-outline">Send Mass Email (WIP Needs Backend Code Still)<div id="sendMassEmailSpinner"></div></button>
|
<button id="sendMassEmailBtn" class="btn btn-primary-outline">Send To All Users<div id="sendMassEmailSpinner"></div></button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -141,13 +154,14 @@
|
||||||
var base = '@Html.GetBaseUrl()';
|
var base = '@Html.GetBaseUrl()';
|
||||||
var url = createBaseUrl(base, '/admin/testmassadminemail');
|
var url = createBaseUrl(base, '/admin/testmassadminemail');
|
||||||
$('#testSendMassEmailSpinner').attr("class", "fa fa-spinner fa-spin");
|
$('#testSendMassEmailSpinner').attr("class", "fa fa-spinner fa-spin");
|
||||||
|
var data = { "Users": "", "Body": $("#massEmailBody").val(), "Subject": $("#massEmailSubject").val() };
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "post",
|
type: "post",
|
||||||
url: url,
|
url: url,
|
||||||
data: $("#massEmailBody").val(),
|
data: data,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if (response) {
|
if (response.result) {
|
||||||
generateNotify(response.message, "success");
|
generateNotify(response.message, "success");
|
||||||
$('#testSendMassEmailSpinner').attr("class", "fa fa-check");
|
$('#testSendMassEmailSpinner').attr("class", "fa fa-check");
|
||||||
} else {
|
} 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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue