The Azure Communication Buddy makes sending E-Mail easy. Find more detailed information on the Azure website.
The IBuddyServiceCollection of the Adliance.AspNetCore.Buddy.Abstractions package offers the AddBuddy method, which provides AddAzureCommunicationEmail extensions to add the E-Mail services.
using Adliance.AspNetCore.Buddy.Email.AzureCommunicationServices;
// ...
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddBuddy()
.AddAzureCommunicationEmail(Configuration.GetSection("Email"),
Configuration.GetSection("AzureCommunicationEmail"))
//...
}Add a section in the configuration of your project and add following configuration:
{
"Email": {
"SenderName": "unused (always taken from config in Azure)",
"SenderAddress": "sender@example.com",
"ReplyToAddress": "reply@example.com",
"RedirectAllEmailsTo": "",
"Disable": false
},
"AzureCommunicationEmail": {
"Endpoint": "https://<your-communication-service-name>.<region>.communication.azure.com/",
"AccessKey": "your-access-key",
"UserEngagementTrackingDisabled": false
}
}Look up your API credentials in your Azure portal.
This code sample shows the usage of the Azure Communication email client. Just call the Send method providing a recipient, subject and a body.
IEmailer emailer = new AzureCommunicationEmailer(azureCommunicationConfig, emailConfig);
await emailer.Send(recipientAddress,
"Descriptive subject line",
"This is the <b>HTML</b> body.",
"This is the **Text** body.");