A Transmitly channel provider for sending Email communications through SMTP using MailKit.
Install from NuGet:
dotnet add package Transmitly.ChannelProvider.Smtpusing Transmitly;
using Transmitly.ChannelProvider.Smtp.Configuration;
ICommunicationsClient communicationsClient = new CommunicationsClientBuilder()
.AddSmtpSupport(options =>
{
options.Host = "smtp.example.com";
options.Port = 587;
options.UserName = "smtp-user";
options.Password = "smtp-password";
})
.AddPipeline("welcome-email", pipeline =>
{
pipeline.AddEmail("welcome@my.app".AsIdentityAddress("Welcome Team"), email =>
{
email.Subject.AddStringTemplate("Welcome to My App");
email.HtmlBody.AddStringTemplate("<h1>Welcome to My App</h1><p>Thanks for joining us.</p><p><a href=\"https://my.app/get-started\">Get started</a></p>");
email.TextBody.AddStringTemplate("Welcome to My App\n\nThanks for joining us.\nGet started: https://my.app/get-started");
});
})
.BuildClient();
var result = await communicationsClient.DispatchAsync(
"welcome-email",
"newuser@my.app".AsIdentityAddress("New User"),
new { });AddSmtpSupport(options => ...) accepts SmtpOptions from Transmitly.ChannelProvider.Smtp.Configuration.
| Option | Required | Default | Description |
|---|---|---|---|
Host |
Yes | null |
SMTP server host name. |
Port |
No | 587 (465 when SocketOptions = SslOnConnect) |
SMTP server port. |
SocketOptions |
No | Auto |
TLS/SSL behavior (None, Auto, SslOnConnect, StartTls, StartTlsWhenAvailable). |
Encoding |
No | UTF8 |
Encoding. |
Credentials |
Conditional | null |
SMTP server credentials. |
UserName |
Conditional | null |
SMTP server username. |
Password |
Conditional | null |
SMTP server password. |
You can register multiple SMTP providers with different providerId values and route communications to a GDPR or non-GDPR SMTP server.
using Transmitly;
using Transmitly.ChannelProvider.Smtp.Configuration;
ICommunicationsClient client = new CommunicationsClientBuilder()
.AddSmtpSupport(o =>
{
o.Host = "smtp.eu-gdpr.example.com";
o.Port = 587;
o.SocketOptions = SecureSocketOptions.StartTls;
o.UserName = "gdpr-user";
o.Password = "gdpr-password";
}, providerId: "gdpr")
.AddSmtpSupport(o =>
{
o.Host = "smtp.global.example.com";
o.Port = 587;
o.SocketOptions = SecureSocketOptions.StartTls;
o.UserName = "non-gdpr-user";
o.Password = "non-gdpr-password";
}, providerId: "non-gdpr")
.AddPipeline("eu-account-alert", pipeline =>
{
pipeline.AddEmail("privacy@my.app".AsIdentityAddress("Privacy Team"), email =>
{
email.Subject.AddStringTemplate("Important account alert");
email.TextBody.AddStringTemplate("There is an update on your account.");
email.AddChannelProviderFilter(Id.ChannelProvider.Smtp("gdpr"));
});
})
.AddPipeline("global-marketing-email", pipeline =>
{
pipeline.AddEmail("news@my.app".AsIdentityAddress("Marketing"), email =>
{
email.Subject.AddStringTemplate("Latest product updates");
email.TextBody.AddStringTemplate("See what's new this month.");
email.AddChannelProviderFilter(Id.ChannelProvider.Smtp("non-gdpr"));
});
})
.BuildClient();For broader concepts such as channels, pipelines, delivery reports, and template engines, see the main Transmitly project.
Copyright (c) Code Impressions, LLC. This open-source project is sponsored and maintained by Code Impressions and is licensed under the Apache License, Version 2.0.