@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.
Files changed (43) hide show
  1. package/README.md +51 -45
  2. package/dist/index.js +341 -214
  3. package/dist/index.js.map +1 -1
  4. package/dist-esm/samples-dev/sendEmailMultipleRecipients.js +11 -24
  5. package/dist-esm/samples-dev/sendEmailMultipleRecipients.js.map +1 -1
  6. package/dist-esm/samples-dev/sendEmailSingleRecipient.js +7 -10
  7. package/dist-esm/samples-dev/sendEmailSingleRecipient.js.map +1 -1
  8. package/dist-esm/samples-dev/sendEmailWithAttachments.js +9 -12
  9. package/dist-esm/samples-dev/sendEmailWithAttachments.js.map +1 -1
  10. package/dist-esm/src/emailClient.js +8 -34
  11. package/dist-esm/src/emailClient.js.map +1 -1
  12. package/dist-esm/src/generated/src/emailRestApiClient.js +53 -10
  13. package/dist-esm/src/generated/src/emailRestApiClient.js.map +1 -1
  14. package/dist-esm/src/generated/src/index.js +11 -0
  15. package/dist-esm/src/generated/src/index.js.map +1 -0
  16. package/dist-esm/src/generated/src/lroImpl.js +25 -0
  17. package/dist-esm/src/generated/src/lroImpl.js.map +1 -0
  18. package/dist-esm/src/generated/src/models/index.js +14 -1
  19. package/dist-esm/src/generated/src/models/index.js.map +1 -1
  20. package/dist-esm/src/generated/src/models/mappers.js +134 -86
  21. package/dist-esm/src/generated/src/models/mappers.js.map +1 -1
  22. package/dist-esm/src/generated/src/models/parameters.js +25 -16
  23. package/dist-esm/src/generated/src/models/parameters.js.map +1 -1
  24. package/dist-esm/src/generated/src/operations/email.js +79 -40
  25. package/dist-esm/src/generated/src/operations/email.js.map +1 -1
  26. package/dist-esm/src/generated/src/operationsInterfaces/email.js +9 -0
  27. package/dist-esm/src/generated/src/operationsInterfaces/email.js.map +1 -0
  28. package/dist-esm/src/generated/src/operationsInterfaces/index.js +9 -0
  29. package/dist-esm/src/generated/src/operationsInterfaces/index.js.map +1 -0
  30. package/dist-esm/src/models.js +1 -1
  31. package/dist-esm/src/models.js.map +1 -1
  32. package/dist-esm/test/public/emailClient.spec.js +98 -127
  33. package/dist-esm/test/public/emailClient.spec.js.map +1 -1
  34. package/dist-esm/test/public/utils/recordedClient.js +46 -32
  35. package/dist-esm/test/public/utils/recordedClient.js.map +1 -1
  36. package/package.json +16 -15
  37. package/types/communication-email.d.ts +147 -134
  38. package/dist-esm/samples-dev/checkMessageStatus.js +0 -46
  39. package/dist-esm/samples-dev/checkMessageStatus.js.map +0 -1
  40. package/dist-esm/src/constants.js +0 -4
  41. package/dist-esm/src/constants.js.map +0 -1
  42. package/dist-esm/src/generated/src/emailRestApiClientContext.js +0 -38
  43. 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
- ```typescript
32
- import { EmailClient } from "@azure/communication-email";
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
- ## Examples
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 `send` function from the `EmailClient`.
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
- ```typescript Snippet:Azure_Communication_Email_Send
45
- const emailMessage: EmailMessage = {
46
- sender: "sender@contoso.com",
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
- email: "customer@domain.com",
66
+ address: "customer@domain.com",
55
67
  displayName: "Customer Name",
56
68
  },
57
69
  ],
58
70
  },
59
71
  };
60
72
 
61
- const response = await emailClient.send(emailMessage);
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
- ```typescript Snippet:Azure_Communication_Email_Send_Multiple_Recipients
69
- const emailMessage: EmailMessage = {
70
- sender: "sender@contoso.com",
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
- email: "customer1@domain.com",
91
+ address: "customer1@domain.com",
79
92
  displayName: "Customer Name 1",
80
93
  },
81
94
  {
82
- email: "customer2@domain.com",
95
+ address: "customer2@domain.com",
83
96
  displayName: "Customer Name 2",
84
97
  },
85
98
  ],
86
- cC: [
99
+ cc: [
87
100
  {
88
- email: "ccCustomer1@domain.com",
101
+ address: "ccCustomer1@domain.com",
89
102
  displayName: " CC Customer 1",
90
103
  },
91
104
  {
92
- email: "ccCustomer2@domain.com",
105
+ address: "ccCustomer2@domain.com",
93
106
  displayName: "CC Customer 2",
94
107
  },
95
108
  ],
96
- bCC: [
109
+ bcc: [
97
110
  {
98
- email: "bccCustomer1@domain.com",
111
+ address: "bccCustomer1@domain.com",
99
112
  displayName: " BCC Customer 1",
100
113
  },
101
114
  {
102
- email: "bccCustomer2@domain.com",
115
+ address: "bccCustomer2@domain.com",
103
116
  displayName: "BCC Customer 2",
104
117
  },
105
118
  ],
106
119
  },
107
120
  };
108
121
 
109
- const response = await emailClient.send(emailMessage);
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
- ```typescript Snippet:Azure_Communication_Email_Send_With_Attachments
130
+ ```javascript Snippet:Azure_Communication_Email_Send_With_Attachments
117
131
  const filePath = "C://readme.txt";
118
132
 
119
- const emailMessage: EmailMessage = {
120
- sender: "sender@contoso.com",
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
- toRecipients: [
140
+ to: [
127
141
  {
128
- email: "customer@domain.com",
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
- attachmentType: "txt",
137
- contentBytesBase64: readFileSync(filePath, "base64"),
150
+ contentType: "text/plain",
151
+ contentInBase64: readFileSync(filePath, "base64"),
138
152
  },
139
153
  ],
140
154
  };
141
155
 
142
- const response = await emailClient.send(emailMessage);
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