@azure/communication-email 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/README.md +183 -0
- package/dist/index.js +668 -0
- package/dist/index.js.map +1 -0
- package/dist-esm/samples-dev/checkMessageStatus.js +46 -0
- package/dist-esm/samples-dev/checkMessageStatus.js.map +1 -0
- package/dist-esm/samples-dev/sendEmailMultipleRecipients.js +59 -0
- package/dist-esm/samples-dev/sendEmailMultipleRecipients.js.map +1 -0
- package/dist-esm/samples-dev/sendEmailSingleRecipient.js +43 -0
- package/dist-esm/samples-dev/sendEmailSingleRecipient.js.map +1 -0
- package/dist-esm/samples-dev/sendEmailWithAttachments.js +50 -0
- package/dist-esm/samples-dev/sendEmailWithAttachments.js.map +1 -0
- package/dist-esm/src/constants.js +4 -0
- package/dist-esm/src/constants.js.map +1 -0
- package/dist-esm/src/emailClient.js +64 -0
- package/dist-esm/src/emailClient.js.map +1 -0
- package/dist-esm/src/generated/src/emailRestApiClient.js +26 -0
- package/dist-esm/src/generated/src/emailRestApiClient.js.map +1 -0
- package/dist-esm/src/generated/src/emailRestApiClientContext.js +38 -0
- package/dist-esm/src/generated/src/emailRestApiClientContext.js.map +1 -0
- package/dist-esm/src/generated/src/models/index.js +9 -0
- package/dist-esm/src/generated/src/models/index.js.map +1 -0
- package/dist-esm/src/generated/src/models/mappers.js +331 -0
- package/dist-esm/src/generated/src/models/mappers.js.map +1 -0
- package/dist-esm/src/generated/src/models/parameters.js +76 -0
- package/dist-esm/src/generated/src/models/parameters.js.map +1 -0
- package/dist-esm/src/generated/src/operations/email.js +96 -0
- package/dist-esm/src/generated/src/operations/email.js.map +1 -0
- package/dist-esm/src/generated/src/operations/index.js +9 -0
- package/dist-esm/src/generated/src/operations/index.js.map +1 -0
- package/dist-esm/src/index.js +5 -0
- package/dist-esm/src/index.js.map +1 -0
- package/dist-esm/src/logger.js +8 -0
- package/dist-esm/src/logger.js.map +1 -0
- package/dist-esm/src/models.js +4 -0
- package/dist-esm/src/models.js.map +1 -0
- package/dist-esm/test/public/emailClient.spec.js +137 -0
- package/dist-esm/test/public/emailClient.spec.js.map +1 -0
- package/dist-esm/test/public/utils/recordedClient.js +46 -0
- package/dist-esm/test/public/utils/recordedClient.js.map +1 -0
- package/package.json +110 -0
- package/types/communication-email.d.ts +200 -0
package/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Microsoft
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
# Azure Communication Email client library for JavaScript
|
2
|
+
|
3
|
+
This package contains a JavaScript/TypeScript SDK for Azure Communication Services for Email.
|
4
|
+
|
5
|
+
## Getting started
|
6
|
+
|
7
|
+
### Prerequisites
|
8
|
+
|
9
|
+
You need an [Azure subscription][azure_sub], a [Communication Service Resource][communication_resource_docs], and an [Email Communication Resource][email_resource_docs] with an active [Domain][domain_overview].
|
10
|
+
|
11
|
+
To create these resource, you can use the [Azure Portal][communication_resource_create_portal], the [Azure PowerShell][communication_resource_create_power_shell], or the [.NET management client library][communication_resource_create_net].
|
12
|
+
|
13
|
+
### Installing
|
14
|
+
|
15
|
+
```bash
|
16
|
+
npm install @azure/communication-email
|
17
|
+
```
|
18
|
+
|
19
|
+
### Browser support
|
20
|
+
|
21
|
+
## Key concepts
|
22
|
+
|
23
|
+
`EmailClient` provides the functionality to send email messages .
|
24
|
+
|
25
|
+
## Examples
|
26
|
+
|
27
|
+
## Authentication
|
28
|
+
|
29
|
+
Email clients can be authenticated using the connection string acquired from an Azure Communication Resource in the [Azure Portal][azure_portal].
|
30
|
+
|
31
|
+
```typescript
|
32
|
+
import { EmailClient } from "@azure/communication-email";
|
33
|
+
|
34
|
+
const connectionString = `endpoint=https://<resource-name>.communication.azure.com/;accessKey=<Base64-Encoded-Key>`;
|
35
|
+
const client = new EmailClient(connectionString);
|
36
|
+
```
|
37
|
+
|
38
|
+
## Examples
|
39
|
+
|
40
|
+
### Send an Email Message
|
41
|
+
|
42
|
+
To send an email message, call the `send` function from the `EmailClient`.
|
43
|
+
|
44
|
+
```typescript Snippet:Azure_Communication_Email_Send
|
45
|
+
const emailMessage: EmailMessage = {
|
46
|
+
sender: "sender@contoso.com",
|
47
|
+
content: {
|
48
|
+
subject: "This is the subject",
|
49
|
+
plainText: "This is the body",
|
50
|
+
},
|
51
|
+
recipients: {
|
52
|
+
to: [
|
53
|
+
{
|
54
|
+
email: "customer@domain.com",
|
55
|
+
displayName: "Customer Name",
|
56
|
+
},
|
57
|
+
],
|
58
|
+
},
|
59
|
+
};
|
60
|
+
|
61
|
+
const response = await emailClient.send(emailMessage);
|
62
|
+
```
|
63
|
+
|
64
|
+
### Send an Email Message to Multiple Recipients
|
65
|
+
|
66
|
+
To send an email message to multiple recipients, add a object for each recipient type and an object for each recipient.
|
67
|
+
|
68
|
+
```typescript Snippet:Azure_Communication_Email_Send_Multiple_Recipients
|
69
|
+
const emailMessage: EmailMessage = {
|
70
|
+
sender: "sender@contoso.com",
|
71
|
+
content: {
|
72
|
+
subject: "This is the subject",
|
73
|
+
plainText: "This is the body",
|
74
|
+
},
|
75
|
+
recipients: {
|
76
|
+
to: [
|
77
|
+
{
|
78
|
+
email: "customer1@domain.com",
|
79
|
+
displayName: "Customer Name 1",
|
80
|
+
},
|
81
|
+
{
|
82
|
+
email: "customer2@domain.com",
|
83
|
+
displayName: "Customer Name 2",
|
84
|
+
},
|
85
|
+
],
|
86
|
+
cC: [
|
87
|
+
{
|
88
|
+
email: "ccCustomer1@domain.com",
|
89
|
+
displayName: " CC Customer 1",
|
90
|
+
},
|
91
|
+
{
|
92
|
+
email: "ccCustomer2@domain.com",
|
93
|
+
displayName: "CC Customer 2",
|
94
|
+
},
|
95
|
+
],
|
96
|
+
bCC: [
|
97
|
+
{
|
98
|
+
email: "bccCustomer1@domain.com",
|
99
|
+
displayName: " BCC Customer 1",
|
100
|
+
},
|
101
|
+
{
|
102
|
+
email: "bccCustomer2@domain.com",
|
103
|
+
displayName: "BCC Customer 2",
|
104
|
+
},
|
105
|
+
],
|
106
|
+
},
|
107
|
+
};
|
108
|
+
|
109
|
+
const response = await emailClient.send(emailMessage);
|
110
|
+
```
|
111
|
+
|
112
|
+
### Send Email with Attachments
|
113
|
+
|
114
|
+
Azure Communication Services support sending email with attachments.
|
115
|
+
|
116
|
+
```typescript Snippet:Azure_Communication_Email_Send_With_Attachments
|
117
|
+
const filePath = "C://readme.txt";
|
118
|
+
|
119
|
+
const emailMessage: EmailMessage = {
|
120
|
+
sender: "sender@contoso.com",
|
121
|
+
content: {
|
122
|
+
subject: "This is the subject",
|
123
|
+
plainText: "This is the body",
|
124
|
+
},
|
125
|
+
recipients: {
|
126
|
+
toRecipients: [
|
127
|
+
{
|
128
|
+
email: "customer@domain.com",
|
129
|
+
displayName: "Customer Name",
|
130
|
+
},
|
131
|
+
],
|
132
|
+
},
|
133
|
+
attachments: [
|
134
|
+
{
|
135
|
+
name: path.basename(filePath),
|
136
|
+
attachmentType: "txt",
|
137
|
+
contentBytesBase64: readFileSync(filePath, "base64"),
|
138
|
+
},
|
139
|
+
],
|
140
|
+
};
|
141
|
+
|
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);
|
153
|
+
```
|
154
|
+
|
155
|
+
## Next steps
|
156
|
+
|
157
|
+
- [Read more about Email in Azure Communication Services][nextsteps]
|
158
|
+
|
159
|
+
## Contributing
|
160
|
+
|
161
|
+
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][cla].
|
162
|
+
|
163
|
+
This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any additional questions or comments.
|
164
|
+
|
165
|
+
<!-- LINKS -->
|
166
|
+
|
167
|
+
[azure_sub]: https://azure.microsoft.com/free/dotnet/
|
168
|
+
[azure_portal]: https://portal.azure.com
|
169
|
+
[cla]: https://cla.microsoft.com
|
170
|
+
[coc]: https://opensource.microsoft.com/codeofconduct/
|
171
|
+
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
|
172
|
+
[coc_contact]: mailto:opencode@microsoft.com
|
173
|
+
[communication_resource_docs]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp
|
174
|
+
[email_resource_docs]: https://aka.ms/acsemail/createemailresource
|
175
|
+
[communication_resource_create_portal]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp
|
176
|
+
[communication_resource_create_power_shell]: https://docs.microsoft.com/powershell/module/az.communication/new-azcommunicationservice
|
177
|
+
[communication_resource_create_net]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-net
|
178
|
+
[package]: https://www.nuget.org/packages/Azure.Communication.Common/
|
179
|
+
[product_docs]: https://aka.ms/acsemail/overview
|
180
|
+
[nextsteps]: https://aka.ms/acsemail/overview
|
181
|
+
[nuget]: https://www.nuget.org/
|
182
|
+
[source]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/communication
|
183
|
+
[domain_overview]: https://aka.ms/acsemail/domainsoverview
|