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.
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:…or, similarly, the (also new)
TRENZ.Lib.RazorMail.System.Net
package, with: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 thepublic 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 this2.0
instead of1.2
.