@azure/communication-email 1.0.0-beta.1 → 1.0.0-beta.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +51 -45
- package/dist/index.js +341 -214
- package/dist/index.js.map +1 -1
- package/dist-esm/samples-dev/sendEmailMultipleRecipients.js +11 -24
- package/dist-esm/samples-dev/sendEmailMultipleRecipients.js.map +1 -1
- package/dist-esm/samples-dev/sendEmailSingleRecipient.js +7 -10
- package/dist-esm/samples-dev/sendEmailSingleRecipient.js.map +1 -1
- package/dist-esm/samples-dev/sendEmailWithAttachments.js +9 -12
- package/dist-esm/samples-dev/sendEmailWithAttachments.js.map +1 -1
- package/dist-esm/src/emailClient.js +8 -34
- package/dist-esm/src/emailClient.js.map +1 -1
- package/dist-esm/src/generated/src/emailRestApiClient.js +53 -10
- package/dist-esm/src/generated/src/emailRestApiClient.js.map +1 -1
- package/dist-esm/src/generated/src/index.js +11 -0
- package/dist-esm/src/generated/src/index.js.map +1 -0
- package/dist-esm/src/generated/src/lroImpl.js +25 -0
- package/dist-esm/src/generated/src/lroImpl.js.map +1 -0
- package/dist-esm/src/generated/src/models/index.js +14 -1
- package/dist-esm/src/generated/src/models/index.js.map +1 -1
- package/dist-esm/src/generated/src/models/mappers.js +134 -86
- package/dist-esm/src/generated/src/models/mappers.js.map +1 -1
- package/dist-esm/src/generated/src/models/parameters.js +25 -16
- package/dist-esm/src/generated/src/models/parameters.js.map +1 -1
- package/dist-esm/src/generated/src/operations/email.js +79 -40
- package/dist-esm/src/generated/src/operations/email.js.map +1 -1
- package/dist-esm/src/generated/src/operationsInterfaces/email.js +9 -0
- package/dist-esm/src/generated/src/operationsInterfaces/email.js.map +1 -0
- package/dist-esm/src/generated/src/operationsInterfaces/index.js +9 -0
- package/dist-esm/src/generated/src/operationsInterfaces/index.js.map +1 -0
- package/dist-esm/src/models.js +1 -1
- package/dist-esm/src/models.js.map +1 -1
- package/dist-esm/test/public/emailClient.spec.js +98 -127
- package/dist-esm/test/public/emailClient.spec.js.map +1 -1
- package/dist-esm/test/public/utils/recordedClient.js +46 -32
- package/dist-esm/test/public/utils/recordedClient.js.map +1 -1
- package/package.json +16 -15
- package/types/communication-email.d.ts +147 -134
- package/dist-esm/samples-dev/checkMessageStatus.js +0 -46
- package/dist-esm/samples-dev/checkMessageStatus.js.map +0 -1
- package/dist-esm/src/constants.js +0 -4
- package/dist-esm/src/constants.js.map +0 -1
- package/dist-esm/src/generated/src/emailRestApiClientContext.js +0 -38
- package/dist-esm/src/generated/src/emailRestApiClientContext.js.map +0 -1
package/README.md
CHANGED
@@ -16,34 +16,46 @@ To create these resource, you can use the [Azure Portal][communication_resource_
|
|
16
16
|
npm install @azure/communication-email
|
17
17
|
```
|
18
18
|
|
19
|
-
### Browser support
|
20
|
-
|
21
|
-
## Key concepts
|
22
|
-
|
23
|
-
`EmailClient` provides the functionality to send email messages .
|
24
|
-
|
25
19
|
## Examples
|
26
20
|
|
21
|
+
`EmailClient` provides the functionality to send email messages.
|
22
|
+
|
27
23
|
## Authentication
|
28
24
|
|
29
25
|
Email clients can be authenticated using the connection string acquired from an Azure Communication Resource in the [Azure Portal][azure_portal].
|
30
26
|
|
31
|
-
```
|
32
|
-
|
27
|
+
```javascript
|
28
|
+
const { EmailClient } = require("@azure/communication-email");
|
33
29
|
|
34
30
|
const connectionString = `endpoint=https://<resource-name>.communication.azure.com/;accessKey=<Base64-Encoded-Key>`;
|
35
31
|
const client = new EmailClient(connectionString);
|
36
32
|
```
|
37
33
|
|
38
|
-
|
34
|
+
You can also authenticate with Azure Active Directory using the [Azure Identity library][azure_identity]. To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the [`@azure/identity`][azure_identity] package:
|
35
|
+
|
36
|
+
```bash
|
37
|
+
npm install @azure/identity
|
38
|
+
```
|
39
|
+
|
40
|
+
The [`@azure/identity`][azure_identity] package provides a variety of credential types that your application can use to do this. The README for @azure/identity provides more details and samples to get you started.
|
41
|
+
AZURE_CLIENT_SECRET, AZURE_CLIENT_ID and AZURE_TENANT_ID environment variables are needed to create a DefaultAzureCredential object.
|
42
|
+
|
43
|
+
```typescript
|
44
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
45
|
+
import { EmailClient } from "@azure/communication-email";
|
46
|
+
|
47
|
+
const endpoint = "https://<resource-name>.communication.azure.com";
|
48
|
+
let credential = new DefaultAzureCredential();
|
49
|
+
const client = new EmailClient(endpoint, credential);
|
50
|
+
```
|
39
51
|
|
40
52
|
### Send an Email Message
|
41
53
|
|
42
|
-
To send an email message, call the `
|
54
|
+
To send an email message, call the `beginSend` function from the `EmailClient`. This will return a poller. You can use this poller to check on the status of the operation and retrieve the result once it's finished.
|
43
55
|
|
44
|
-
```
|
45
|
-
const
|
46
|
-
|
56
|
+
```javascript Snippet:Azure_Communication_Email_Send
|
57
|
+
const message = {
|
58
|
+
senderAddress: "sender@contoso.com",
|
47
59
|
content: {
|
48
60
|
subject: "This is the subject",
|
49
61
|
plainText: "This is the body",
|
@@ -51,23 +63,24 @@ const emailMessage: EmailMessage = {
|
|
51
63
|
recipients: {
|
52
64
|
to: [
|
53
65
|
{
|
54
|
-
|
66
|
+
address: "customer@domain.com",
|
55
67
|
displayName: "Customer Name",
|
56
68
|
},
|
57
69
|
],
|
58
70
|
},
|
59
71
|
};
|
60
72
|
|
61
|
-
const
|
73
|
+
const poller = await emailClient.beginSend(message);
|
74
|
+
const response = await poller.pollUntilDone();
|
62
75
|
```
|
63
76
|
|
64
77
|
### Send an Email Message to Multiple Recipients
|
65
78
|
|
66
79
|
To send an email message to multiple recipients, add a object for each recipient type and an object for each recipient.
|
67
80
|
|
68
|
-
```
|
69
|
-
const
|
70
|
-
|
81
|
+
```javascript Snippet:Azure_Communication_Email_Send_Multiple_Recipients
|
82
|
+
const message = {
|
83
|
+
senderAddress: "sender@contoso.com",
|
71
84
|
content: {
|
72
85
|
subject: "This is the subject",
|
73
86
|
plainText: "This is the body",
|
@@ -75,57 +88,58 @@ const emailMessage: EmailMessage = {
|
|
75
88
|
recipients: {
|
76
89
|
to: [
|
77
90
|
{
|
78
|
-
|
91
|
+
address: "customer1@domain.com",
|
79
92
|
displayName: "Customer Name 1",
|
80
93
|
},
|
81
94
|
{
|
82
|
-
|
95
|
+
address: "customer2@domain.com",
|
83
96
|
displayName: "Customer Name 2",
|
84
97
|
},
|
85
98
|
],
|
86
|
-
|
99
|
+
cc: [
|
87
100
|
{
|
88
|
-
|
101
|
+
address: "ccCustomer1@domain.com",
|
89
102
|
displayName: " CC Customer 1",
|
90
103
|
},
|
91
104
|
{
|
92
|
-
|
105
|
+
address: "ccCustomer2@domain.com",
|
93
106
|
displayName: "CC Customer 2",
|
94
107
|
},
|
95
108
|
],
|
96
|
-
|
109
|
+
bcc: [
|
97
110
|
{
|
98
|
-
|
111
|
+
address: "bccCustomer1@domain.com",
|
99
112
|
displayName: " BCC Customer 1",
|
100
113
|
},
|
101
114
|
{
|
102
|
-
|
115
|
+
address: "bccCustomer2@domain.com",
|
103
116
|
displayName: "BCC Customer 2",
|
104
117
|
},
|
105
118
|
],
|
106
119
|
},
|
107
120
|
};
|
108
121
|
|
109
|
-
const
|
122
|
+
const poller = await emailClient.beginSend(message);
|
123
|
+
const response = await poller.pollUntilDone();
|
110
124
|
```
|
111
125
|
|
112
126
|
### Send Email with Attachments
|
113
127
|
|
114
128
|
Azure Communication Services support sending email with attachments.
|
115
129
|
|
116
|
-
```
|
130
|
+
```javascript Snippet:Azure_Communication_Email_Send_With_Attachments
|
117
131
|
const filePath = "C://readme.txt";
|
118
132
|
|
119
|
-
const
|
120
|
-
|
133
|
+
const message = {
|
134
|
+
senderAddress: "sender@contoso.com",
|
121
135
|
content: {
|
122
136
|
subject: "This is the subject",
|
123
137
|
plainText: "This is the body",
|
124
138
|
},
|
125
139
|
recipients: {
|
126
|
-
|
140
|
+
to: [
|
127
141
|
{
|
128
|
-
|
142
|
+
address: "customer@domain.com",
|
129
143
|
displayName: "Customer Name",
|
130
144
|
},
|
131
145
|
],
|
@@ -133,23 +147,13 @@ const emailMessage: EmailMessage = {
|
|
133
147
|
attachments: [
|
134
148
|
{
|
135
149
|
name: path.basename(filePath),
|
136
|
-
|
137
|
-
|
150
|
+
contentType: "text/plain",
|
151
|
+
contentInBase64: readFileSync(filePath, "base64"),
|
138
152
|
},
|
139
153
|
],
|
140
154
|
};
|
141
155
|
|
142
|
-
const response = await emailClient.send(
|
143
|
-
```
|
144
|
-
|
145
|
-
### Get Email Message Status
|
146
|
-
|
147
|
-
The result from the `send` call contains a `messageId` which can be used to query the status of the email.
|
148
|
-
|
149
|
-
```typescript Snippet:Azure_Communication_Email_GetSendStatus
|
150
|
-
const messageId = await emailClient.send(emailMessage);
|
151
|
-
|
152
|
-
const status = await emailClient.getSendStatus(messageId);
|
156
|
+
const response = await emailClient.send(message);
|
153
157
|
```
|
154
158
|
|
155
159
|
## Next steps
|
@@ -170,6 +174,8 @@ This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For m
|
|
170
174
|
[coc]: https://opensource.microsoft.com/codeofconduct/
|
171
175
|
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
|
172
176
|
[coc_contact]: mailto:opencode@microsoft.com
|
177
|
+
[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential
|
178
|
+
[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity
|
173
179
|
[communication_resource_docs]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp
|
174
180
|
[email_resource_docs]: https://aka.ms/acsemail/createemailresource
|
175
181
|
[communication_resource_create_portal]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp
|