Skip to main content

Curiosus.EMail.SMTP

NuGet Downloads Coverage

SMTP implementation of IEMailSender from Curiosus.EMail, built on MailKit. Use it to send e-mails through any SMTP server.

Installation​

dotnet add package Curiosus.EMail.SMTP

Usage​

Options (SmtpEMailOptions, validated on registration):

Smtp:
SmtpServer: smtp.example.com # required
SmtpPort: 587 # default 25
SmtpLogin: noreply@example.com # required
SmtpPassword: <secret> # required
EMailFrom: noreply@example.com # required
SenderName: Example # required
ReplyTo: support@example.com # optional
IgnoreIncorrectExtraParamsType: false
using Curiosus.EMail;
using Curiosus.EMail.Smtp;

var smtpOptions = builder.Configuration.GetSection("Smtp").Get<SmtpEMailOptions>()!;
builder.Services.AddSmtpEMailSender(smtpOptions); // ISmtpEMailSender and, by default, IEMailSender

// in a service that receives IEMailSender sender: send with the default sender settings
await sender.SendAsync("user@example.com", "Invoice", "Your invoice is attached", cancellationToken: ct);

// override sender address/name/reply-to for one message
await sender.SendAsync("user@example.com", "Hi", "<p>Hi!</p>", true,
new SmtpEMailExtraParams(eMailFrom: "sales@example.com", senderName: "Sales"), ct);

Pass useAsDefaultSender: false to register only ISmtpEMailSender when another provider is the default IEMailSender. Each send opens a new connection with SecureSocketOptions.Auto and authenticates with the login and password. Note: the sender currently accepts any server TLS certificate (certificate validation and revocation checks are disabled).

See also​