diff --git a/MediaBrowser.Plugins.SmtpNotifications/Api/ServerApiEntryPoints.cs b/MediaBrowser.Plugins.SmtpNotifications/Api/ServerApiEntryPoints.cs index f9b17a3..6cc584f 100644 --- a/MediaBrowser.Plugins.SmtpNotifications/Api/ServerApiEntryPoints.cs +++ b/MediaBrowser.Plugins.SmtpNotifications/Api/ServerApiEntryPoints.cs @@ -19,26 +19,23 @@ public class TestNotification : IReturnVoid class ServerApiEndpoints : IService { private readonly IUserManager _userManager; - private readonly IEncryptionManager _encryption; private readonly ILogger _logger; - public ServerApiEndpoints(IUserManager userManager, ILogger logger, IEncryptionManager encryption) + public ServerApiEndpoints(IUserManager userManager, ILogger logger) { _userManager = userManager; _logger = logger; - _encryption = encryption; } public void Post(TestNotification request) { - var task = new Notifier(_logger, _encryption).SendNotification(new UserNotification + var task = new Notifier(_logger).SendNotification(new UserNotification { Date = DateTime.UtcNow, Description = "This is a test notification from Emby Server", Level = Model.Notifications.NotificationLevel.Normal, Name = "Emby: Test Notification", User = _userManager.GetUserById(request.UserID) - }, CancellationToken.None); Task.WaitAll(task); diff --git a/MediaBrowser.Plugins.SmtpNotifications/Configuration/PluginConfiguration.cs b/MediaBrowser.Plugins.SmtpNotifications/Configuration/PluginConfiguration.cs index f5eab58..c123aaf 100644 --- a/MediaBrowser.Plugins.SmtpNotifications/Configuration/PluginConfiguration.cs +++ b/MediaBrowser.Plugins.SmtpNotifications/Configuration/PluginConfiguration.cs @@ -25,8 +25,7 @@ public class SMTPOptions public bool UseCredentials { get; set; } public string Username { get; set; } public string Password { get; set; } - public string PwData { get; set; } - public string MediaBrowserUserId { get; set; } + public string UserId { get; set; } public bool SSL { get; set; } public SMTPOptions() diff --git a/MediaBrowser.Plugins.SmtpNotifications/Configuration/config.html b/MediaBrowser.Plugins.SmtpNotifications/Configuration/config.html index b723d33..58d7a4a 100644 --- a/MediaBrowser.Plugins.SmtpNotifications/Configuration/config.html +++ b/MediaBrowser.Plugins.SmtpNotifications/Configuration/config.html @@ -5,12 +5,9 @@
-
-
-
@@ -73,27 +70,19 @@
-
diff --git a/MediaBrowser.Plugins.SmtpNotifications/MediaBrowser.Plugins.SmtpNotifications.csproj b/MediaBrowser.Plugins.SmtpNotifications/MediaBrowser.Plugins.SmtpNotifications.csproj index 7bdb2ea..a2d3add 100644 --- a/MediaBrowser.Plugins.SmtpNotifications/MediaBrowser.Plugins.SmtpNotifications.csproj +++ b/MediaBrowser.Plugins.SmtpNotifications/MediaBrowser.Plugins.SmtpNotifications.csproj @@ -1,9 +1,9 @@ - netstandard2.0; - 2.0.0 - 2.0.0 + netstandard2.0 + 3.0.0 + 3.0.0 diff --git a/MediaBrowser.Plugins.SmtpNotifications/Notifier.cs b/MediaBrowser.Plugins.SmtpNotifications/Notifier.cs index 93df2ad..208225b 100644 --- a/MediaBrowser.Plugins.SmtpNotifications/Notifier.cs +++ b/MediaBrowser.Plugins.SmtpNotifications/Notifier.cs @@ -14,13 +14,11 @@ namespace MediaBrowser.Plugins.SmtpNotifications { public class Notifier : INotificationService { - private readonly IEncryptionManager _encryption; private readonly ILogger _logger; public static Notifier Instance { get; private set; } - public Notifier(ILogger logger, IEncryptionManager encryption) + public Notifier(ILogger logger) { - _encryption = encryption; _logger = logger; Instance = this; @@ -36,7 +34,7 @@ public bool IsEnabledForUser(User user) private SMTPOptions GetOptions(User user) { return Plugin.Instance.Configuration.Options - .FirstOrDefault(i => string.Equals(i.MediaBrowserUserId, user.Id.ToString("N"), StringComparison.OrdinalIgnoreCase)); + .FirstOrDefault(i => string.Equals(i.UserId, user.Id.ToString("N"), StringComparison.OrdinalIgnoreCase)); } public string Name @@ -55,10 +53,6 @@ private void TrySendNotification(UserNotification request, CancellationToken can try { SendNotificationCore(request, cancellationToken); - } - catch (OperationCanceledException) - { - } catch (Exception ex) { @@ -89,10 +83,13 @@ private void SendNotificationCore(UserNotification request, CancellationToken ca _logger.LogInformation("Sending email {to} with subject {subject}", options.EmailTo, mail.Subject); - if (options.UseCredentials) + if (options.UseCredentials && !string.IsNullOrEmpty(options.Username) && !string.IsNullOrEmpty(options.Password)) + { + client.Credentials = new NetworkCredential(options.Username, options.Password); + } + else { - var pw = string.IsNullOrWhiteSpace(options.Password) ? _encryption.DecryptString(options.PwData) : options.Password; - client.Credentials = new NetworkCredential(options.Username, pw); + _logger.LogError("Cannot use credentials for email to {user} because the username or password is missing", options.EmailTo); } try diff --git a/MediaBrowser.Plugins.SmtpNotifications/Plugin.cs b/MediaBrowser.Plugins.SmtpNotifications/Plugin.cs index 7cfaf39..6b43da4 100644 --- a/MediaBrowser.Plugins.SmtpNotifications/Plugin.cs +++ b/MediaBrowser.Plugins.SmtpNotifications/Plugin.cs @@ -16,12 +16,9 @@ namespace MediaBrowser.Plugins.SmtpNotifications /// public class Plugin : BasePlugin, IHasWebPages { - private readonly IEncryptionManager _encryption; - - public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, IEncryptionManager encryption) + public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) : base(applicationPaths, xmlSerializer) { - _encryption = encryption; Instance = this; } @@ -60,7 +57,7 @@ public override string Description { get { - return "Sends notifications via email."; + return "Send SMTP email notifications"; } } diff --git a/build.yaml b/build.yaml index 9a5652d..9ae2bfd 100644 --- a/build.yaml +++ b/build.yaml @@ -1,13 +1,13 @@ --- name: "jellyfin-plugin-emailnotifications" guid: "cfa0f7f4-4155-4d71-849b-d6598dc4c5bb" -version: "2" # Please increment with each pull request +version: "3" # Please increment with each pull request jellyfin_version: "10.3.0" # The earliest binary-compatible version owner: "jellyfin" -nicename: "Email Notifications" +nicename: "Email" description: "Send SMTP email notifications" overview: "Send SMTP email notifications" -category: "General" +category: "Notifications" artifacts: - "MediaBrowser.Plugins.SmtpNotifications.dll" build_type: "dotnet"