diff --git a/mixtape/Mails/Dispatchers/Postmark/PostmarkDispatcher.cs b/mixtape/Mails/Dispatchers/Postmark/PostmarkDispatcher.cs deleted file mode 100644 index 106f287e..00000000 --- a/mixtape/Mails/Dispatchers/Postmark/PostmarkDispatcher.cs +++ /dev/null @@ -1,120 +0,0 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Options; -using PostmarkDotNet; -using PostmarkDotNet.Model; - -namespace Mixtape.Mails.Dispatchers.Postmark; - -public class PostmarkDispatcher : IMailDispatcher -{ - protected PostmarkClient Postmark { get; set; } - - protected PostmarkAdminClient PostmarkAdmin { get; set; } - - protected MailOptions Options { get; set; } - - protected IWebHostEnvironment Env { get; set; } - - - public PostmarkDispatcher(IOptionsMonitor monitor, IWebHostEnvironment env) - { - Options = monitor.CurrentValue; - PostmarkOptions opts = Options.Postmark ?? new(); - Postmark = new(opts.ServerToken); - PostmarkAdmin = new(opts.AccountToken); - Env = env; - - monitor.OnChange(_opts => - { - Options = _opts; - Postmark = new(_opts.Postmark?.ServerToken); - }); - } - - - /// - public async Task IsSenderSupported(string email) - { - if (email.IsNullOrWhiteSpace() || Options.Postmark.AccountToken.IsNullOrEmpty()) - { - return true; - } - - try - { - email = email.FullTrim(); - PostmarkSenderSignatureList signatures = await PostmarkAdmin.GetSenderSignaturesAsync(); - return signatures.SenderSignatures.Any(x => x.Confirmed && x.EmailAddress.Equals(email, StringComparison.InvariantCultureIgnoreCase)); - } - catch - { - return true; - } - } - - - /// - public async Task Send(Mail message, CancellationToken token = default) - { - PostmarkMessage data = new() - { - // to addresses - To = message.To.ToString(), - Cc = message.CC.ToString(), - Bcc = message.Bcc.ToString(), - - // from address - From = message.From.ToString(), - ReplyTo = message.ReplyToList.ToString(), - - // subject - Subject = message.Subject, - - // tracking - TrackLinks = LinkTrackingOptions.None, - TrackOpens = false, - - // configuration - MessageStream = Options.Postmark.MessageStream, - //Tag = message.Template?.Key, - Metadata = message.Metadata - }; - - // set attachments - foreach (System.Net.Mail.Attachment attachment in message.Attachments) - { - data.AddAttachment(attachment.ContentStream, attachment.Name, attachment.ContentType.MediaType, attachment.ContentId); - } - - // set body - if (!message.IsBodyHtml) - { - data.TextBody = message.Body; - } - else - { - data.HtmlBody = message.Body; - } - - // finally sends the message - PostmarkResponse response = await Postmark.SendMessageAsync(data); - - if (response.ErrorCode > 0) - { - throw new PostmarkSendException($"Could not send message via Postmark API. Code: {response.ErrorCode}, Message: {response.Message}"); - } - } - - - /// - public void Dispose() { } -} - - -public class PostmarkSendException : Exception -{ - public PostmarkSendException() : base() { } - - public PostmarkSendException(string message) : base(message) { } -} diff --git a/mixtape/Mails/Dispatchers/Postmark/PostmarkOptions.cs b/mixtape/Mails/Dispatchers/Postmark/PostmarkOptions.cs deleted file mode 100644 index 1c44f6e3..00000000 --- a/mixtape/Mails/Dispatchers/Postmark/PostmarkOptions.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Mixtape.Mails.Dispatchers.Postmark; - -public class PostmarkOptions -{ - public string ServerToken { get; set; } - - public string AccountToken { get; set; } - - public string MessageStream { get; set; } = "outbound"; -} \ No newline at end of file diff --git a/mixtape/Mails/MailOptions.cs b/mixtape/Mails/MailOptions.cs index e7543c42..2ef75249 100644 --- a/mixtape/Mails/MailOptions.cs +++ b/mixtape/Mails/MailOptions.cs @@ -1,5 +1,4 @@ using Mixtape.Mails.Dispatchers.Lettermint; -using Mixtape.Mails.Dispatchers.Postmark; using Mixtape.Mails.Dispatchers.Scaleway; namespace Mixtape.Mails; @@ -22,8 +21,6 @@ public class MailOptions public string SenderName { get; set; } - public PostmarkOptions Postmark { get; set; } - public ScalewayOptions Scaleway { get; set; } public LettermintOptions Lettermint { get; set; } diff --git a/mixtape/Mails/MixtapeMailModule.cs b/mixtape/Mails/MixtapeMailModule.cs index 55b05fa9..ebe94cc9 100644 --- a/mixtape/Mails/MixtapeMailModule.cs +++ b/mixtape/Mails/MixtapeMailModule.cs @@ -1,5 +1,4 @@ using Mixtape.Mails.Dispatchers; -using Mixtape.Mails.Dispatchers.Postmark; using Mixtape.Mails.Dispatchers.Scaleway; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; diff --git a/mixtape/mixtape.csproj b/mixtape/mixtape.csproj index 38e63954..b538fd5b 100644 --- a/mixtape/mixtape.csproj +++ b/mixtape/mixtape.csproj @@ -17,7 +17,6 @@ -