Added logging around the Newsletter #717

pull/750/head
Jamie.Rees 8 years ago
parent 88b1472f88
commit b55f1ed231

@ -105,6 +105,7 @@ namespace PlexRequests.Services.Jobs
public void Test() public void Test()
{ {
Log.Debug("Starting Test Newsletter");
var settings = NewsletterSettings.GetSettings(); var settings = NewsletterSettings.GetSettings();
Start(settings, true); Start(settings, true);
} }
@ -113,19 +114,32 @@ namespace PlexRequests.Services.Jobs
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
var plexSettings = PlexSettings.GetSettings(); var plexSettings = PlexSettings.GetSettings();
Log.Debug("Got Plex Settings");
var libs = Api.GetLibrarySections(plexSettings.PlexAuthToken, plexSettings.FullUri); var libs = Api.GetLibrarySections(plexSettings.PlexAuthToken, plexSettings.FullUri);
Log.Debug("Getting Plex Library Sections");
var tvSection = libs.Directories.FirstOrDefault(x => x.type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase)); var tvSection = libs.Directories.FirstOrDefault(x => x.type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase));
Log.Debug("Filtered sections for TV");
var movieSection = libs.Directories.FirstOrDefault(x => x.type.Equals(PlexMediaType.Movie.ToString(), StringComparison.CurrentCultureIgnoreCase)); var movieSection = libs.Directories.FirstOrDefault(x => x.type.Equals(PlexMediaType.Movie.ToString(), StringComparison.CurrentCultureIgnoreCase));
Log.Debug("Filtered sections for Movies");
var recentlyAddedTv = Api.RecentlyAdded(plexSettings.PlexAuthToken, plexSettings.FullUri, tvSection.Key); var recentlyAddedTv = Api.RecentlyAdded(plexSettings.PlexAuthToken, plexSettings.FullUri, tvSection.Key);
Log.Debug("Got RecentlyAdded TV Shows");
var recentlyAddedMovies = Api.RecentlyAdded(plexSettings.PlexAuthToken, plexSettings.FullUri, movieSection.Key); var recentlyAddedMovies = Api.RecentlyAdded(plexSettings.PlexAuthToken, plexSettings.FullUri, movieSection.Key);
Log.Debug("Got RecentlyAdded Movies");
Log.Debug("Started Generating Movie HTML");
GenerateMovieHtml(recentlyAddedMovies, plexSettings, sb); GenerateMovieHtml(recentlyAddedMovies, plexSettings, sb);
Log.Debug("Finished Generating Movie HTML");
Log.Debug("Started Generating TV HTML");
GenerateTvHtml(recentlyAddedTv, plexSettings, sb); GenerateTvHtml(recentlyAddedTv, plexSettings, sb);
Log.Debug("Finished Generating TV HTML");
var template = new RecentlyAddedTemplate(); var template = new RecentlyAddedTemplate();
var html = template.LoadTemplate(sb.ToString()); var html = template.LoadTemplate(sb.ToString());
Log.Debug("Loaded the template");
Send(newletterSettings, html, plexSettings, testEmail); Send(newletterSettings, html, plexSettings, testEmail);
} }
@ -247,6 +261,7 @@ namespace PlexRequests.Services.Jobs
private void Send(NewletterSettings newletterSettings, string html, PlexSettings plexSettings, bool testEmail = false) private void Send(NewletterSettings newletterSettings, string html, PlexSettings plexSettings, bool testEmail = false)
{ {
Log.Debug("Entering Send");
var settings = EmailSettings.GetSettings(); var settings = EmailSettings.GetSettings();
if (!settings.Enabled || string.IsNullOrEmpty(settings.EmailHost)) if (!settings.Enabled || string.IsNullOrEmpty(settings.EmailHost))
@ -255,11 +270,13 @@ namespace PlexRequests.Services.Jobs
} }
var body = new BodyBuilder { HtmlBody = html, TextBody = "This email is only available on devices that support HTML." }; var body = new BodyBuilder { HtmlBody = html, TextBody = "This email is only available on devices that support HTML." };
var message = new MimeMessage var message = new MimeMessage
{ {
Body = body.ToMessageBody(), Body = body.ToMessageBody(),
Subject = "New Content on Plex!", Subject = "New Content on Plex!",
}; };
Log.Debug("Created Plain/HTML MIME body");
if (!testEmail) if (!testEmail)
{ {
@ -284,6 +301,7 @@ namespace PlexRequests.Services.Jobs
} }
} }
} }
message.Bcc.Add(new MailboxAddress(settings.EmailUsername, settings.RecipientEmail)); // Include the admin message.Bcc.Add(new MailboxAddress(settings.EmailUsername, settings.RecipientEmail)); // Include the admin
message.From.Add(new MailboxAddress(settings.EmailUsername, settings.EmailSender)); message.From.Add(new MailboxAddress(settings.EmailUsername, settings.EmailSender));
@ -302,7 +320,9 @@ namespace PlexRequests.Services.Jobs
client.Authenticate(settings.EmailUsername, settings.EmailPassword); client.Authenticate(settings.EmailUsername, settings.EmailPassword);
} }
Log.Info("sending message to {0} \r\n from: {1}\r\n Are we authenticated: {2}", message.To, message.From, client.IsAuthenticated); Log.Info("sending message to {0} \r\n from: {1}\r\n Are we authenticated: {2}", message.To, message.From, client.IsAuthenticated);
Log.Debug("Sending");
client.Send(message); client.Send(message);
Log.Debug("Sent");
client.Disconnect(true); client.Disconnect(true);
} }
} }

@ -1050,12 +1050,13 @@ namespace PlexRequests.UI.Modules
{ {
try try
{ {
Log.Debug("Clicked TEST");
RecentlyAdded.Test(); RecentlyAdded.Test();
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)
{ {
Log.Error(e);
return Response.AsJson(new JsonResponseModel { Result = false, Message = e.Message }); return Response.AsJson(new JsonResponseModel { Result = false, Message = e.Message });
} }
} }

Loading…
Cancel
Save