JSPM

@azure/communication-email

1.0.0-alpha.20221017.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 77439
  • Score
    100M100P100Q165573F
  • License MIT

The is the JS Client SDK for email. This SDK enables users to send emails and get the status of sent email message.

Package Exports

  • @azure/communication-email
  • @azure/communication-email/dist-esm/src/index.js
  • @azure/communication-email/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@azure/communication-email) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Azure Communication Email client library for JavaScript

This package contains a JavaScript/TypeScript SDK for Azure Communication Services for Email.

Getting started

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.

Installing

npm install @azure/communication-email

Examples

EmailClient provides the functionality to send email messages .

Authentication

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

const { EmailClient } = require("@azure/communication-email");

const connectionString = `endpoint=https://<resource-name>.communication.azure.com/;accessKey=<Base64-Encoded-Key>`;
const client = new EmailClient(connectionString);

Send an Email Message

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

const emailMessage = {
  sender: "sender@contoso.com",
  content: {
    subject: "This is the subject",
    plainText: "This is the body",
  },
  recipients: {
    to: [
      {
        email: "customer@domain.com",
        displayName: "Customer Name",
      },
    ],
  },
};

const response = await emailClient.send(emailMessage);

Send an Email Message to Multiple Recipients

To send an email message to multiple recipients, add a object for each recipient type and an object for each recipient.

const emailMessage = {
  sender: "sender@contoso.com",
  content: {
    subject: "This is the subject",
    plainText: "This is the body",
  },
  recipients: {
    to: [
      {
        email: "customer1@domain.com",
        displayName: "Customer Name 1",
      },
      {
        email: "customer2@domain.com",
        displayName: "Customer Name 2",
      },
    ],
    cc: [
      {
        email: "ccCustomer1@domain.com",
        displayName: " CC Customer 1",
      },
      {
        email: "ccCustomer2@domain.com",
        displayName: "CC Customer 2",
      },
    ],
    bcc: [
      {
        email: "bccCustomer1@domain.com",
        displayName: " BCC Customer 1",
      },
      {
        email: "bccCustomer2@domain.com",
        displayName: "BCC Customer 2",
      },
    ],
  },
};

const response = await emailClient.send(emailMessage);

Send Email with Attachments

Azure Communication Services support sending email with attachments.

const filePath = "C://readme.txt";

const emailMessage = {
  sender: "sender@contoso.com",
  content: {
    subject: "This is the subject",
    plainText: "This is the body",
  },
  recipients: {
    to: [
      {
        email: "customer@domain.com",
        displayName: "Customer Name",
      },
    ],
  },
  attachments: [
    {
      name: path.basename(filePath),
      attachmentType: "txt",
      contentBytesBase64: readFileSync(filePath, "base64"),
    },
  ],
};

const response = await emailClient.send(emailMessage);

Get Email Message Status

The result from the send call contains a messageId which can be used to query the status of the email.

const response = await emailClient.send(emailMessage);

const status = await emailClient.getSendStatus(response.messageId);

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.