Azure.Communication.Email 1.0.0-beta.1

Prefix Reserved
This is a prerelease version of Azure.Communication.Email.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Azure.Communication.Email --version 1.0.0-beta.1                
NuGet\Install-Package Azure.Communication.Email -Version 1.0.0-beta.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Azure.Communication.Email" Version="1.0.0-beta.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Azure.Communication.Email --version 1.0.0-beta.1                
#r "nuget: Azure.Communication.Email, 1.0.0-beta.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Azure.Communication.Email as a Cake Addin
#addin nuget:?package=Azure.Communication.Email&version=1.0.0-beta.1&prerelease

// Install Azure.Communication.Email as a Cake Tool
#tool nuget:?package=Azure.Communication.Email&version=1.0.0-beta.1&prerelease                

Azure Communication Email client library for .NET

This package contains a C# SDK for Azure Communication Services for Email.

Source code | Package (NuGet) | Product documentation

Getting started

Install the package

Install the Azure Communication Email client library for .NET with NuGet:

dotnet add package Azure.Communication.Email --prerelease

Prerequisites

You need an Azure subscription, a Communication Service Resource, and an Email Communication Resource with an active Domain.

To create these resource, you can use the Azure Portal, the Azure PowerShell, or the .NET management client library.

Key concepts

EmailClient provides the functionality to send email messages .

Using statements

using Azure.Communication.Email;
using Azure.Communication.Email.Models;

Authenticate the client

Email clients can be authenticated using the connection string acquired from an Azure Communication Resource in the Azure Portal.

var connectionString = "<connection_string>"; // Find your Communication Services resource in the Azure portal
EmailClient client = new EmailClient(connectionString);

Alternatively, Email clients can also be authenticated using a valid token credential. With this option, AZURE_CLIENT_SECRET, AZURE_CLIENT_ID and AZURE_TENANT_ID environment variables need to be set up for authentication.

string endpoint = "<endpoint_url>";
TokenCredential tokenCredential = new DefaultAzureCredential();
tokenCredential = new DefaultAzureCredential();
EmailClient client = new EmailClient(new Uri(endpoint), tokenCredential);

Examples

Send an Email Message

To send an email message, call the Send or SendAsync function from the EmailClient.

// Create the email content
var emailContent = new EmailContent("This is the subject");
emailContent.PlainText = "This is the body";

// Create the recipient list
var emailRecipients = new EmailRecipients(
    new List<EmailAddress>
    {
        new EmailAddress(
            email: "<recipient email address>"
            displayName: "<recipient displayname>"
    });

// Create the EmailMessage
var emailMessage = new EmailMessage(
    sender: "<Send email address>" // The email address of the domain registered with the Communication Services resource
    emailContent,
    emailRecipients);

SendEmailResult sendResult = client.Send(emailMessage);

Console.WriteLine($"Email id: {sendResult.MessageId}");

Send an Email Message to Multiple Recipients

To send an email message to multiple recipients, add an EmailAddress object for each recipent type to the EmailRecipient object.

// Create the email content
var emailContent = new EmailContent("This is the subject");
emailContent.PlainText = "This is the body";

// Create the To list
var toRecipients = new List<EmailAddress>
{
    new EmailAddress(
        email: "<recipient email address>"
        displayName: "<recipient displayname>"
    new EmailAddress(
        email: "<recipient email address>"
        displayName: "<recipient displayname>"
};

// Create the CC list
var ccRecipients = new List<EmailAddress>
{
    new EmailAddress(
        email: "<recipient email address>"
        displayName: "<recipient displayname>"
    new EmailAddress(
        email: "<recipient email address>"
        displayName: "<recipient displayname>"
};

// Create the BCC list
var bccRecipients = new List<EmailAddress>
{
    new EmailAddress(
        email: "<recipient email address>"
        displayName: "<recipient displayname>"
    new EmailAddress(
        email: "<recipient email address>"
        displayName: "<recipient displayname>"
};

var emailRecipients = new EmailRecipients(toRecipients, ccRecipients, bccRecipients);

// Create the EmailMessage
var emailMessage = new EmailMessage(
    sender: "<Send email address>" // The email address of the domain registered with the Communication Services resource
    emailContent,
    emailRecipients);

SendEmailResult sendResult = client.Send(emailMessage);

Console.WriteLine($"Email id: {sendResult.MessageId}");

Send Email with Attachments

Azure Communication Services support sending email swith attachments. See EmailAttachmentType for a list of supported attachments

// Create the EmailMessage
var emailMessage = new EmailMessage(
    sender: "<Send email address>" // The email address of the domain registered with the Communication Services resource
    emailContent,
    emailRecipients);

var filePath = "<path to your file>";
var attachmentName = "<name of your attachment>"
EmailAttachmentType attachmentType = EmailAttachmentType.Txt;

// Convert the file content into a Base64 string
byte[] bytes = File.ReadAllBytes(filePath);
string attachmentFileInBytes = Convert.ToBase64String(bytes);
var emailAttachment = new EmailAttachment(attachmentName, attachmentType, attachmentFileInBytes);

emailMessage.Attachments.Add(emailAttachment);

SendEmailResult sendResult = client.Send(emailMessage);

Get Email Message Status

The EmailSendResult from the Send call contains a MessageId which can be used to query the status of the email.

SendEmailResult sendResult = client.Send(emailMessage);

SendStatusResult status = client.GetSendStatus(sendResult.MessageId);

Troubleshooting

A RequestFailedException is thrown as a service response for any unsuccessful requests. The exception contains information about what response code was returned from the service.

Next steps

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (30)

Showing the top 5 NuGet packages that depend on Azure.Communication.Email:

Package Downloads
OrchardCore.Application.Cms.Core.Targets

Orchard Core CMS is a Web Content Management System (CMS) built on top of the Orchard Core Framework. Converts the application into a modular OrchardCore CMS application with TheAdmin theme but without any front-end Themes.

OrchardCore.Application.Cms.Targets

Orchard Core CMS is a Web Content Management System (CMS) built on top of the Orchard Core Framework. Converts the application into a modular OrchardCore CMS application with following themes. - TheAdmin Theme - SafeMode Theme - TheAgency Theme - TheBlog Theme - TheComingSoon Theme - TheTheme theme

WATG.Common

WATG library of commonly used and shared functionalities

DataJuggler.BlazorGallery

A project template for creating a Blazor Image Gallery project that uses SQL Server for a backend. You will need SQL Server or SQL Server Express to run this project. See the Read Me for more info. Watch this video to see a demo https://youtu.be/yQz1dqYiy2g.

FonsecaFramework.Azure

Azure Connection Library

GitHub repositories (4)

Showing the top 4 popular GitHub repositories that depend on Azure.Communication.Email:

Repository Stars
OrchardCMS/OrchardCore
Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
platformplatform/PlatformPlatform
Alpha state. A platform designed for building enterprise-grade, multi-tenant products using Azure, .NET, React, TypeScript, Infrastructure as Code, etc.
VedAstro/VedAstro
A non-profit, open source project to make Vedic Astrology easily available to all.
Azure-Samples/communication-services-AI-customer-service-sample
A sample app for the customer support center running in Azure, using Azure Communication Services and Azure OpenAI for text and voice bots.
Version Downloads Last updated
1.1.0-beta.2 2,610 9/26/2024
1.1.0-beta.1 8,418 7/11/2024
1.0.1 1,775,887 8/18/2023
1.0.0 362,831 3/31/2023
1.0.0-beta.4 29,219 3/16/2023
1.0.0-beta.3 1,667 3/14/2023
1.0.0-beta.2 5,669 3/7/2023
1.0.0-beta.1 319,342 5/24/2022