Skip to main content

Configuring Email Providers

To send transactional emails, form submission notifications, and identity verification links, you must configure an email provider in your Endatix API application. Endatix uses a builder pattern to easily register and configure your preferred email service during application startup.

Currently, Endatix provides built-in support for:

  • Mailgun
  • SendGrid
  • Standard SMTP

Activating the Email Provider​

To activate your chosen email provider, you need to modify your application's entry point (typically Program.cs). Use the ConfigureEndatixWithDefaults extension method to specify which provider the infrastructure should use.

Here is an example of how to register Mailgun as your active email provider:

Program.cs
builder.Host.ConfigureEndatixWithDefaults(endatix =>
{
endatix.Infrastructure.Integrations.AddEmail<MailgunEmailSender, MailgunSettings>();
});

To use a different provider, simply swap the generic type parameters with the corresponding sender and settings classes (e.g., SmtpEmailSender and SmtpSettings for standard SMTP).

info

The SMTP provider is the default one and does not require explicit activation.

Providing the Settings​

Once the provider is activated in your code, you must supply the necessary credentials and configuration values in your appsettings.json (or via environment variables).

appsettings.json
{
"Endatix": {
"Integrations": {
"Email": {
"MailgunSettings": {
"ApiKey": "key-your_mailgun_api_key",
"Domain": "mg.yourdomain.com",
"BaseUrl": "https://api.mailgun.net/v3/"
}
}
}
}
}
info

For a complete list of required and optional properties for all supported email integrations (Mailgun, SendGrid, and SMTP), and for identity template sender addresses, see Email Settings. After the API is running, verify the provider and templates in Hub.

Upgrade a custom SMTP transport to MailKit 5​

If you override SmtpEmailSender.CreateTransport(), rebuild your extension against MailKit 5 and align any direct MIME references with MimeKit.Core 5. Do not keep a MimeKit 4.x reference alongside it: both assemblies define types such as MimeMessage, which causes compiler error CS0433. If you only configure the built-in SMTP provider, you do not need to change your settings.

If you implement IMailTransport, migrate the Send and SendAsync overloads (with and without FormatOptions) to take an ISendRequest. Read the message from request.Message and return SendResult or Task<SendResult> instead of a response string. Implement DisposeAsync() if your transport does not inherit it from MailService.

If your SmtpClient subclass overrides sender or recipient acceptance callbacks, move those overrides to a SmtpSendRequest subclass and pass an instance of it when your transport sends the message.

See the MailKit 5 porting guide for the complete migration.