Substantive.Polycloud.EmailSender 9.1.0-build20251217r2
Library for sending an email with an SMTP server or email service providers such as SendGrid, MailGun, AWS SES.
Installation
1. Add configuration to the appsettings.json
Add the below configuration for SMTP Server :
SmtpClientOptionsis for config SMTP server provider like Outlook, Gmail, Yahoo
{
"EmailSenderOptions": {
"EmailServiceProvider": "Smtp",
"LimitFileUploadSize": 1048576,
"LimitBCC": 100,
"DefaultSender": {
"Name": "Test Sender Name",
"EmailAddress": "testsendemail@gmail.com"
},
"SmtpClientOptions": {
"Server": "smtp.gmail.com",
"Port": 465,
"User": "test@gmail.com",
"Password": "apppassword",
"UseSsl": true,
"RequiresAuthentication": true,
"PreferredEncoding": "",
"UsePickupDirectory": false,
"MailPickupDirectory": ""
},
}
}
Add the below configuration for MailGun service provider :
{
"EmailSenderOptions": {
"EmailServiceProvider": "MailGun",
"LimitFileUploadSize": 1048576,
"LimitBCC": 100,
"DefaultSender": {
"Name": "Test Sender Name",
"EmailAddress": "testsendemail@gmail.com"
},
"MailGunOptions": {
"DomainName": "sandboxcf5f41bbf2f84f15a386c60e253b5fe9.mailgun.org",
"APIKey": "key-8d32c046d7f14ada8d5ba8253e3e30de",
"Region": "USA"
}
}
}
Add the below configuration for SendGrid service provider :
{
"EmailSenderOptions": {
"EmailServiceProvider": "Smtp",
"LimitFileUploadSize": 1048576,
"LimitBCC": 100,
"DefaultSender": {
"Name": "Test Sender Name",
"EmailAddress": "testsendemail@gmail.com"
},
"SendGridOptions": {
"APIKey": "xxxxx",
"SandBoxMode": false,
}
}
}
2. Load configuration and add dependencies to the program.cs
EmailSenderOptions emailSenderOptions = new();
builder.Configuration.GetSection(nameof(EmailSenderOptions)).Bind(emailSenderOptions);
builder.Services.AddEmailSender(options => options.SmtpClientOptions = emailSenderOptions.SmtpClientOptions);
Usage
- Inject IEmailSender into class.
private readonly IEmailSender emailSender;
public EmailSenderController(IEmailSender emailSender)
{
this.emailSender = emailSender;
}
- Call method to send an email.
emailSender.SendEmailAsync(recieveEmailAddress, subject, body, HttpContext.RequestAborted);
FAQs and Troubleshoots
SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required
Make sure the username and password are correct.
- If using Gmail SMTP you need to enable 2FA and generate another password for application-specific password (a different password from your main email). For more information, check out this link.
RazorLight.RazorLightException: 'Can't load metadata reference from the entry assembly.
Make sure PreserveCompilationContext is set to true in the entry .csproj file.
<PreserveCompilationContext>true</PreserveCompilationContext>
AWS SES Configuration
To create a credential to use SMTP AWS need to use an verify email address or email domain and an SMTP account.
Create SMTP credential
- Go to Amazon SES and click
SMTP settingsmenu. - Click
Create SMTP credentialsbutton. - Input IAM username.
- Click
Show User SMTP Security Credentialsto expand the username and password for using SMTP credential.
- Go to Amazon SES and click
Create verify email.
- Go to Amazon SES and click
Configuration>Verified identitiesmenu. - Click
Create Identitybutton. - Choose
Email addressto verify this email sender email can using send email service. - Go to email and open verify email.
- Go to Amazon SES and click
Note: If in AWS SES Dashboard page display Your Amazon SES account is in the sandbox in Asia Pacific (Singapore).
It mean you can only send from verified domains and email addressed, and only send to verified domains and email addresses.
Showing the top 20 packages that depend on Substantive.Polycloud.EmailSender.
| Packages | Downloads |
|---|---|
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
3 |
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
4 |
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
6 |
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
7 |
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
8 |
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
9 |
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
11 |
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
14 |
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
16 |
|
Substantive.Metapackage.Backends
A metapackage contains all Substantive backend building blocks.
|
3 |
.NET 10.0
- Substantive.ComponentModel (>= 9.1.0-build20251217R2)
- FluentEmail.Core (>= 3.0.2)
- FluentEmail.MailKit (>= 3.0.2)
- FluentEmail.Mailgun (>= 3.0.2)
- FluentEmail.Razor (>= 3.0.2)
- FluentEmail.SendGrid (>= 3.0.2)
- FluentEmail.Smtp (>= 3.0.2)
- FluentValidation (>= 12.1.1)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.1)
- System.ComponentModel.Annotations (>= 5.0.0)