finish implementing mass email feature

pull/1047/head
dhruvb14 8 years ago
parent 7a2a057346
commit ca94694076

@ -124,6 +124,7 @@
<Compile Include="SettingModels\AuthenticationSettings.cs" />
<Compile Include="SettingModels\DiscordNotificationSettings.cs" />
<Compile Include="SettingModels\EmbySettings.cs" />
<Compile Include="SettingModels\MassEmailSettings.cs" />
<Compile Include="SettingModels\RadarrSettings.cs" />
<Compile Include="SettingModels\WatcherSettings.cs" />
<Compile Include="SettingModels\ExternalSettings.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; }
}
}

@ -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);
}
}

@ -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("</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");
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");

@ -148,7 +148,7 @@
</td>
</tr>
<tr>
<td align="center">
<td align="left">
{@MASSEMAIL}
</td>
</tr>

@ -1252,8 +1252,16 @@ namespace Ombi.UI.Modules.Admin
{
try
{
var settings = this.Bind<MassEmailSettings>();
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" });
}
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<MassEmailSettings>();
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", "<br/>"), settings.Subject);
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to All users" });
}
catch (Exception e)
{

@ -7,46 +7,48 @@
<form class="form-horizontal" method="POST" id="mainForm">
<fieldset>
<legend>Newsletter Settings</legend>
<div style="padding:10px">
<!-- Email Nofication Section -->
<div class="form-group">
<div class="checkbox">
<!-- Email Nofication Section -->
<div class="form-group">
<div class="checkbox">
<small>Note: This will require you to setup your email notifications</small>
<br />
@if (Model.SendRecentlyAddedEmail)
{
<input type="checkbox" id="SendRecentlyAddedEmail" name="SendRecentlyAddedEmail" checked="checked"><label for="SendRecentlyAddedEmail">Enable newsletter</label>
}
else
{
<input type="checkbox" id="SendRecentlyAddedEmail" name="SendRecentlyAddedEmail"><label for="SendRecentlyAddedEmail">Enable newsletter</label>
}
<small>Note: This will require you to setup your email notifications</small>
<br />
@if (Model.SendRecentlyAddedEmail)
{
<input type="checkbox" id="SendRecentlyAddedEmail" name="SendRecentlyAddedEmail" checked="checked"><label for="SendRecentlyAddedEmail">Enable newsletter</label>
}
else
{
<input type="checkbox" id="SendRecentlyAddedEmail" name="SendRecentlyAddedEmail"><label for="SendRecentlyAddedEmail">Enable newsletter</label>
}
</div>
</div>
</div>
<div class="form-group">
<br>
<label for="CustomUsers" class="control-label">Email Addresses to Send to (For users that are not in your User Management section)</label>
<small>You can add multiple email addresses by using the ; delimiter</small>
<div>
<input type="text" class="form-control form-control-custom " placeholder="first@address.com;second@address.com" id="CustomUsers" name="CustomUsers" value="@Model.CustomUsers">
<div class="form-group">
<br>
<label for="CustomUsers" class="control-label">Email Addresses to Send to (For users that are not in your User Management section)</label>
<small>You can add multiple email addresses by using the ; delimiter</small>
<div>
<input type="text" class="form-control form-control-custom " placeholder="first@address.com;second@address.com" id="CustomUsers" name="CustomUsers" value="@Model.CustomUsers">
</div>
</div>
</div>
<div class="form-group">
<div>
<button id="recentlyAddedBtn" class="btn btn-primary-outline">Send test email to Admin <div id="testEmailSpinner"></div></button>
<div class="form-group">
<div>
<button id="recentlyAddedBtn" class="btn btn-primary-outline">Send test email to Admin <div id="testEmailSpinner"></div></button>
</div>
</div>
</div>
<br />
<br />
<div class="form-group">
<div>
<button type="submit" id="save" class="btn btn-primary-outline">Save</button>
<br />
<br />
<div class="form-group">
<div>
<button type="submit" id="save" class="btn btn-primary-outline">Save</button>
</div>
</div>
</div>
<!-- Email Nofication Section -->
@ -57,21 +59,32 @@
<form id="massemail" class="form-horizontal">
<fieldset>
<legend>Mass Email</legend>
<div class="form-group">
<label for="massEmailBody" class="control-label">Send mass email to all users who recieve newsletter</label>
<div style="padding:10px">
<div class="form-group">
<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>
<small>Supports HTML</small>
<textarea id="massEmailBody" class="form-control" rows="5"></textarea>
<small>Supports HTML</small>
</div>
<div class="form-group">
<div>
<button id="testSendMassEmailBtn" class="btn btn-primary-outline">Send Test to Admin<div id="testSendMassEmailSpinner"></div></button>
</div>
</div>
<div class="form-group">
<div>
<button id="sendMassEmailBtn" class="btn btn-primary-outline">Send Mass Email (WIP Needs Backend Code Still)<div id="sendMassEmailSpinner"></div></button>
<div class="form-group">
<div>
<button id="testSendMassEmailBtn" class="btn btn-primary-outline">Send Test to Admin<div id="testSendMassEmailSpinner"></div></button>
</div>
</div>
<div class="form-group">
<div>
<button id="sendMassEmailBtn" class="btn btn-primary-outline">Send To All Users<div id="sendMassEmailSpinner"></div></button>
</div>
</div>
</div>
</fieldset>
@ -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");
}
});
});
});
</script>

Loading…
Cancel
Save