E Mail
Description
Email providers in FlexBase expose a unified interface (IFlexEmailProvider) for sending transactional email via SMTP, SendGrid, AWS SES, Azure Communication Services, and more.
Your application code should depend on IFlexEmailProvider.
Important concepts
IFlexEmailProvideris the contract: send viaSendAsync(...),SendHtmlAsync(...),SendToManyAsync(...),SendBulkAsync(...), andSendTemplatedAsync(...).Provider bridge: generated infrastructure commonly registers
IFlexEmailProviderBridge(which also implementsIFlexEmailProvider) so behavior can be overridden safely.Templates are optional: template rendering is supported via
IFlexEmailTemplateEngine(and provider-specific template features vary).
Configuration in DI
Only register the provider—Flex auto-wires generated PostBus handlers/plugins that consume the interface.
public static class OtherApplicationServicesConfig
{
public static IServiceCollection AddOtherApplicationServices(
this IServiceCollection services,
IConfiguration configuration)
{
// Pick ONE (or register multiple with different compositions).
services.AddFlexSmtpEmailProvider(configuration);
// services.AddFlexSendGridEmailProvider(configuration);
// services.AddFlexAwsSesEmailProvider(configuration);
// services.AddFlexAzureCommunicationEmailProvider(configuration);
return services;
}
}appsettings.json
Email provider configuration is read from FlexBase:Providers:Email:<Provider>.
Examples (template-based)
This mirrors the generated PostBus handler template shape. You do not register the handler manually.
Provider considerations
Keep secrets (SMTP password, SendGrid API key, AWS keys, ACS connection string) out of source control.
Use
TestConnectionAsync(...)during startup checks/health probes.public async Task SendWelcomeEmailAsync(string email, string name) { var result = await _emailProvider.SendAsync( to: email, subject: "Welcome!", body: $"Hello {name}, welcome to our platform!" );
} }
Full Message Object
Templated Emails
Bulk Emails
Attachments
Key Points to Consider
Best Practices
Use Templates - Define templates for common emails (welcome, reset, etc.)
Validate Emails - Use
ValidateEmailFormat()before sendingHandle Errors - Always check
IsSuccessand log failuresUse Console in Dev - Avoid sending real emails during development
Include Text Fallback - Set both
HtmlBodyandTextBodyTest Connection - Use
TestConnectionAsync()on startupMonitor Delivery - Track
MessageIdfor delivery status
Email Validation
Error Handling
Testing Connection
Multiple Providers
Examples
Complete Email Service
Testing
See Also
Message Providers - SMS and push notifications
FlexEmail Provider Reference - Detailed API documentation
Email Provider Guide - Advanced features
Last updated