AppMailClient is a light-weight client for sending mail to an AppMailRelay server. If you don't want to mess with SMTP, just post web api calls to the AppMailRelay, which handles the smtp bit.
Send()
calls are returned with a pending status, since the Relay server queues the messages.
That is good enough for many apps, but if confirmation is important, Status()
can be used to check for a status up to 10 minutes or so after sending.
# Add package to project
dotnet add package AppMailClient -s <internal-artifactory>
// Startup.cs -- configure dependency
public void ConfigureServices(IServiceCollection services)
{
//services.AddAppMailClient(() => Configuration.GetSection("AppMail"); // scoped options
services.AddAppMailClient(() => Configuration.GetSection("AppMail").Get<AppMailClient.Options>());
}
// Service.cs -- inject dependency
public SomeService(IAppMailClient mailClient) { ... }
"AppMail": {
"Url": "https://appmail.relay.local/msg", # relay endpoint
"Key": "client#secret", # obtain from relay admin
"From": "Sender <[email protected]>", # optional, default at relay
"CcRecipients": "[email protected]; [email protected]", #optional, additional cc's for every message
"BccRecipients": "[email protected]; [email protected]" #optional, additional bcc's for every message
}
Email addresses can be Display Name <[email protected]>
or just [email protected]
and are separated by ;
.
Sometimes an app doesn't know/care who the sender is, but still wants to Bcc them. MailMessage.BccSender can be set to true to achieve this.