@azure/communication-email 1.0.1-alpha.20250122.2 → 1.0.1-alpha.20250127.1

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -24,8 +24,8 @@ npm install @azure/communication-email
24
24
 
25
25
  Email clients can be authenticated using the connection string acquired from an Azure Communication Resource in the [Azure Portal][azure_portal].
26
26
 
27
- ```javascript
28
- const { EmailClient } = require("@azure/communication-email");
27
+ ```ts snippet:ReadmeSampleCreateClient_ConnectionString
28
+ import { EmailClient } from "@azure/communication-email";
29
29
 
30
30
  const connectionString = `endpoint=https://<resource-name>.communication.azure.com/;accessKey=<Base64-Encoded-Key>`;
31
31
  const client = new EmailClient(connectionString);
@@ -40,7 +40,7 @@ npm install @azure/identity
40
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
41
  AZURE_CLIENT_SECRET, AZURE_CLIENT_ID and AZURE_TENANT_ID environment variables are needed to create a DefaultAzureCredential object.
42
42
 
43
- ```typescript
43
+ ```ts snippet:ReadmeSampleCreateClient_AAD
44
44
  import { DefaultAzureCredential } from "@azure/identity";
45
45
  import { EmailClient } from "@azure/communication-email";
46
46
 
@@ -53,7 +53,14 @@ const client = new EmailClient(endpoint, credential);
53
53
 
54
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.
55
55
 
56
- ```javascript Snippet:Azure_Communication_Email_Send
56
+ ```ts snippet:ReadmeSample_SendEmail
57
+ import { DefaultAzureCredential } from "@azure/identity";
58
+ import { EmailClient } from "@azure/communication-email";
59
+
60
+ const endpoint = "https://<resource-name>.communication.azure.com";
61
+ const credential = new DefaultAzureCredential();
62
+ const client = new EmailClient(endpoint, credential);
63
+
57
64
  const message = {
58
65
  senderAddress: "sender@contoso.com",
59
66
  content: {
@@ -70,7 +77,7 @@ const message = {
70
77
  },
71
78
  };
72
79
 
73
- const poller = await emailClient.beginSend(message);
80
+ const poller = await client.beginSend(message);
74
81
  const response = await poller.pollUntilDone();
75
82
  ```
76
83
 
@@ -78,7 +85,14 @@ const response = await poller.pollUntilDone();
78
85
 
79
86
  To send an email message to multiple recipients, add a object for each recipient type and an object for each recipient.
80
87
 
81
- ```javascript Snippet:Azure_Communication_Email_Send_Multiple_Recipients
88
+ ```ts snippet:ReadmeSample_SendEmailToMultipleRecipients
89
+ import { DefaultAzureCredential } from "@azure/identity";
90
+ import { EmailClient } from "@azure/communication-email";
91
+
92
+ const endpoint = "https://<resource-name>.communication.azure.com";
93
+ const credential = new DefaultAzureCredential();
94
+ const client = new EmailClient(endpoint, credential);
95
+
82
96
  const message = {
83
97
  senderAddress: "sender@contoso.com",
84
98
  content: {
@@ -119,7 +133,7 @@ const message = {
119
133
  },
120
134
  };
121
135
 
122
- const poller = await emailClient.beginSend(message);
136
+ const poller = await client.beginSend(message);
123
137
  const response = await poller.pollUntilDone();
124
138
  ```
125
139
 
@@ -127,8 +141,17 @@ const response = await poller.pollUntilDone();
127
141
 
128
142
  Azure Communication Services support sending email with attachments.
129
143
 
130
- ```javascript Snippet:Azure_Communication_Email_Send_With_Attachments
131
- const filePath = "C://readme.txt";
144
+ ```ts snippet:ReadmeSample_SendEmailWithAttachments
145
+ import { DefaultAzureCredential } from "@azure/identity";
146
+ import { EmailClient } from "@azure/communication-email";
147
+ import { basename } from "node:path";
148
+ import { readFileSync } from "node:fs";
149
+
150
+ const endpoint = "https://<resource-name>.communication.azure.com";
151
+ const credential = new DefaultAzureCredential();
152
+ const client = new EmailClient(endpoint, credential);
153
+
154
+ const filePath = "path/to/readme.txt";
132
155
 
133
156
  const message = {
134
157
  senderAddress: "sender@contoso.com",
@@ -146,14 +169,14 @@ const message = {
146
169
  },
147
170
  attachments: [
148
171
  {
149
- name: path.basename(filePath),
172
+ name: basename(filePath),
150
173
  contentType: "text/plain",
151
174
  contentInBase64: readFileSync(filePath, "base64"),
152
175
  },
153
176
  ],
154
177
  };
155
178
 
156
- const poller = await emailClient.beginSend(message);
179
+ const poller = await client.beginSend(message);
157
180
  const response = await poller.pollUntilDone();
158
181
  ```
159
182
 
@@ -162,23 +185,36 @@ const response = await poller.pollUntilDone();
162
185
  Azure Communication Services support sending email with inline attachments.
163
186
  Adding an optional `contentId` parameter to an `attachment` will make it an inline attachment.
164
187
 
165
- ```javascript Snippet:Azure_Communication_Email_Send_With_Attachments
166
- const imageBuffer = await fs.readFile("C:/path/to/my_inline_image.jpg");
188
+ ```ts snippet:ReadmeSample_SendEmailWithInlineAttachments
189
+ import { DefaultAzureCredential } from "@azure/identity";
190
+ import { EmailClient } from "@azure/communication-email";
191
+ import { readFileSync } from "node:fs";
192
+
193
+ const endpoint = "https://<resource-name>.communication.azure.com";
194
+ const credential = new DefaultAzureCredential();
195
+ const client = new EmailClient(endpoint, credential);
196
+
197
+ const imageBuffer = readFileSync("path/to/my_inline_image.jpg");
167
198
  const contentInBase64 = imageBuffer.toString("base64");
168
199
 
169
200
  const message = {
170
- senderAddress: senderAddress,
201
+ senderAddress: "sender@contoso.com",
171
202
  content: {
172
203
  subject: "This is the subject",
173
204
  plainText: "This is the body",
174
205
  html: '<html>This is the body<br /><img src="cid:inline_image" /></html>',
175
206
  },
176
207
  recipients: {
177
- to: [{ address: recipientAddress, displayName: "Customer Name" }],
208
+ to: [
209
+ {
210
+ address: "customer@domain.com",
211
+ displayName: "Customer Name",
212
+ },
213
+ ],
178
214
  },
179
215
  attachments: [
180
216
  {
181
- name: "myinlineimage.jpg",
217
+ name: "my_inline_image.jpg",
182
218
  contentType: "image/jpeg",
183
219
  contentInBase64: contentInBase64,
184
220
  contentId: "inline_image",
@@ -186,10 +222,22 @@ const message = {
186
222
  ],
187
223
  };
188
224
 
189
- const poller = await emailClient.beginSend(message);
225
+ const poller = await client.beginSend(message);
190
226
  const response = await poller.pollUntilDone();
191
227
  ```
192
228
 
229
+ ## Troubleshooting
230
+
231
+ ### Logging
232
+
233
+ Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
234
+
235
+ ```ts snippet:SetLogLevel
236
+ import { setLogLevel } from "@azure/logger";
237
+
238
+ setLogLevel("info");
239
+ ```
240
+
193
241
  ## Next steps
194
242
 
195
243
  - [Read more about Email in Azure Communication Services][nextsteps]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure/communication-email",
3
- "version": "1.0.1-alpha.20250122.2",
3
+ "version": "1.0.1-alpha.20250127.1",
4
4
  "description": "The is the JS Client SDK for email. This SDK enables users to send emails and get the status of sent email message.",
5
5
  "author": "Microsoft Corporation",
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "unit-test": "npm run unit-test:node && npm run unit-test:browser",
31
31
  "unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
32
32
  "unit-test:node": "dev-tool run test:vitest",
33
- "update-snippets": "echo skipped"
33
+ "update-snippets": "dev-tool run update-snippets"
34
34
  },
35
35
  "files": [
36
36
  "dist/",
@@ -59,14 +59,15 @@
59
59
  "@azure-tools/test-utils-vitest": ">=1.0.0-alpha <1.0.0-alphb",
60
60
  "@azure/dev-tool": ">=1.0.0-alpha <1.0.0-alphb",
61
61
  "@azure/eslint-plugin-azure-sdk": ">=3.0.0-alpha <3.0.0-alphb",
62
+ "@azure/identity": "^4.5.0",
62
63
  "@types/node": "^18.0.0",
63
- "@vitest/browser": "^2.1.5",
64
- "@vitest/coverage-istanbul": "^2.1.5",
64
+ "@vitest/browser": "^3.0.3",
65
+ "@vitest/coverage-istanbul": "^3.0.3",
65
66
  "dotenv": "^16.0.0",
66
67
  "eslint": "^9.9.0",
67
- "playwright": "^1.48.2",
68
+ "playwright": "^1.49.1",
68
69
  "typescript": "~5.7.2",
69
- "vitest": "^2.1.5"
70
+ "vitest": "^3.0.3"
70
71
  },
71
72
  "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-email/",
72
73
  "bugs": {
File without changes