This guide will walk you through the essential steps to start sending emails with Azure Communication Services. We'll cover setting up your resource, authenticating, and sending your first email using our SDKs.

Prerequisites

  • An Azure subscription. If you don't have one, create a free account.
  • An Azure Communication Services resource. If you don't have one, create one now.
  • The Azure Communication Services Email SDK.
  • A programming environment (e.g., Node.js, .NET, Python).

Steps to Send Your First Email

1

Provision an Email Domain

Before you can send emails, you need to provision an email domain within your Azure Communication Services resource. This involves verifying ownership of a domain or using a managed domain provided by Azure.

Learn More: Provision Email Domain
2

Install the SDK

Install the Azure Communication Services Email SDK for your preferred programming language. Here's an example for Node.js using npm:

npm install @azure/communication-email

For other languages, please refer to the SDK documentation.

3

Authenticate and Send

Initialize the Email Client with your connection string and then use the send method to send an email. Replace placeholders with your actual values.


// Import the necessary classes
import { EmailClient, EmailMessage, SendEmailResult } from "@azure/communication-email";

// Replace with your actual connection string
const connectionString = "YOUR_ACS_CONNECTION_STRING";
const client = new EmailClient(connectionString);

async function main() {
    const message: EmailMessage = {
        senderAddress: "donotreply@YOUR_DOMAIN.com", // Replace with your verified sender domain
        content: {
            subject: "Hello from Azure Communication Services!",
            html: "

This is an HTML email sent from Azure Communication Services

You can customize this content.

", plainText: "This is a plain text email sent from Azure Communication Services. You can customize this content." }, recipients: { to: [{ address: "recipient@example.com" }] // Replace with the recipient's email address } }; try { console.log("Sending email..."); const poller = await client.beginSend(message); const result: SendEmailResult = await poller.pollUntilDone(); console.log("Email sent successfully!", result); } catch (error) { console.error("Failed to send email:", error); } } main();

Ensure you have set up your environment variables or securely managed your connection string.

Next Steps

  • Explore advanced features like templates, attachments, and delivery status tracking.
  • Integrate email sending into your applications and workflows.
  • Review best practices for email deliverability.