trenz-gmbh / TRENZ.Lib.RazorMail

Templated transactional e-mail using Razor
MIT License
2 stars 0 forks source link

Feature/separate mailsenders #10

Closed chucker closed 2 months ago

chucker commented 2 months ago

Fixes #4, although it isn't quite DI.

Fixes #3.

This removes the dependency on both System.Net.Mail and MailKit+MimeKit in the core project, and instead makes MailSender abstract (and therefore pluggable).

You then reference either the new TRENZ.Lib.RazorMail.MailKit NuGet package, with:

        var mail = new MailKitMailSender(from: request.From,
            to: new[] { (MailAddress)request.To }.ToList(),
            renderedMail);

        await mail.SendAsync(SmtpAccount);

…or, similarly, the (also new) TRENZ.Lib.RazorMail.System.Net package, with:

        var mail = new SystemNetMailSender(from: request.From,
            to: new[] { (MailAddress)request.To }.ToList(),
            renderedMail);

        await mail.SendAsync(SmtpAccount);

This is mostly just a refactor (90% of the code is just moved between files), but some code was replaced to be less tightly coupled. For example, the public static implicit operator System.Net.Mail.Attachment(MailAttachment attachment) operator has been replaced with the public static System.Net.Mail.Attachment ToAttachment(this MailAttachment attachment) extension method. Some code has also been modernized/simplified.

Technically, this is a breaking change of the public API (MailSender can no longer be used directly), so we may want to call this 2.0 instead of 1.2.

ricardoboss commented 2 months ago

Fixes #4?