From b55f1ed231ce26ae39cfbb5904f6bbcaa37cc813 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Thu, 8 Dec 2016 16:10:26 +0000 Subject: [PATCH] Added logging around the Newsletter #717 --- PlexRequests.Services/Jobs/RecentlyAdded.cs | 22 +++++++++++++++++++- PlexRequests.UI/Modules/Admin/AdminModule.cs | 3 ++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/PlexRequests.Services/Jobs/RecentlyAdded.cs b/PlexRequests.Services/Jobs/RecentlyAdded.cs index 7706da615..24fa5b58c 100644 --- a/PlexRequests.Services/Jobs/RecentlyAdded.cs +++ b/PlexRequests.Services/Jobs/RecentlyAdded.cs @@ -105,6 +105,7 @@ namespace PlexRequests.Services.Jobs public void Test() { + Log.Debug("Starting Test Newsletter"); var settings = NewsletterSettings.GetSettings(); Start(settings, true); } @@ -113,19 +114,32 @@ namespace PlexRequests.Services.Jobs { var sb = new StringBuilder(); var plexSettings = PlexSettings.GetSettings(); + Log.Debug("Got Plex Settings"); 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)); + Log.Debug("Filtered sections for TV"); 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); + Log.Debug("Got RecentlyAdded TV Shows"); 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); + Log.Debug("Finished Generating Movie HTML"); + Log.Debug("Started Generating TV HTML"); GenerateTvHtml(recentlyAddedTv, plexSettings, sb); + Log.Debug("Finished Generating TV HTML"); var template = new RecentlyAddedTemplate(); var html = template.LoadTemplate(sb.ToString()); + Log.Debug("Loaded the template"); 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) { + Log.Debug("Entering Send"); var settings = EmailSettings.GetSettings(); 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 message = new MimeMessage { Body = body.ToMessageBody(), Subject = "New Content on Plex!", }; + Log.Debug("Created Plain/HTML MIME body"); if (!testEmail) { @@ -284,6 +301,7 @@ namespace PlexRequests.Services.Jobs } } } + message.Bcc.Add(new MailboxAddress(settings.EmailUsername, settings.RecipientEmail)); // Include the admin message.From.Add(new MailboxAddress(settings.EmailUsername, settings.EmailSender)); @@ -302,7 +320,9 @@ namespace PlexRequests.Services.Jobs 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.Debug("Sending"); client.Send(message); + Log.Debug("Sent"); client.Disconnect(true); } } diff --git a/PlexRequests.UI/Modules/Admin/AdminModule.cs b/PlexRequests.UI/Modules/Admin/AdminModule.cs index a9367c1bc..97ac58f14 100644 --- a/PlexRequests.UI/Modules/Admin/AdminModule.cs +++ b/PlexRequests.UI/Modules/Admin/AdminModule.cs @@ -1050,12 +1050,13 @@ namespace PlexRequests.UI.Modules { try { + Log.Debug("Clicked TEST"); RecentlyAdded.Test(); 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 }); } }