Skip to content

Commit afaa6fe

Browse files
authored
Merge pull request #211432 from yogeshmo/main
Adding advanced usage guide for Email Service
2 parents e4f42ab + faacfd0 commit afaa6fe

File tree

6 files changed

+260
-30
lines changed

6 files changed

+260
-30
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: include file
3+
description: include file
4+
author: yogeshmo
5+
manager: koagbakp
6+
services: azure-communication-services
7+
ms.author: ymohanraj
8+
ms.date: 09/16/2022
9+
ms.topic: include
10+
ms.service: azure-communication-services
11+
ms.custom: private_preview, event-tier1-build-2022
12+
---
13+
14+
15+
| Status Name | Description |
16+
| ----------- | ------------|
17+
| Queued | The email has been placed in the queue for delivery. |
18+
| OutForDelivery | The email is currently en route to its recipient(s). |
19+
| Dropped | The email message was dropped before the delivery could be successfully completed. |

articles/communication-services/quickstarts/email/includes/send-email-java.md

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,7 @@ if(timeout)
172172
}
173173
```
174174

175-
| Status Name | Description |
176-
| ----------- | ------------|
177-
| Queued | The email has been placed in the queue for delivery. |
178-
| OutForDelivery | The email is currently en route to its recipient(s). |
179-
| Dropped | The email message was dropped before the delivery could be successfully completed. |
180-
181-
175+
[!INCLUDE [Email Message Status](./email-message-status.md)]
182176

183177
## Run the code
184178

@@ -199,3 +193,66 @@ if(timeout)
199193
```console
200194
mvn exec:java -Dexec.mainClass="com.communication.quickstart.App" -Dexec.cleanupDaemonThreads=false
201195
```
196+
197+
## Sample code
198+
199+
You can download the sample app from [GitHub](https://github.com/Azure-Samples/communication-services-java-quickstarts/tree/main/send-email)
200+
201+
## Advanced
202+
203+
### Send an email message to multiple recipients
204+
205+
We can define multiple recipients by adding additional EmailAddresses to the EmailRecipients object. These addresses can be added as `To`, `CC`, or `BCC` recipients.
206+
207+
```java
208+
EmailAddress toEmailAddress1 = new EmailAddress("<[email protected]>");
209+
EmailAddress toEmailAddress2 = new EmailAddress("<[email protected]>");
210+
211+
EmailAddress ccEmailAddress = new EmailAddress("<[email protected]>");
212+
EmailAddress bccEmailAddress = new EmailAddress("<[email protected]>");
213+
214+
ArrayList<EmailAddress> toAddressList = new ArrayList<>();
215+
toAddressList.add(toEmailAddress1);
216+
toAddressList.add(toEmailAddress2);
217+
218+
ArrayList<EmailAddress> ccAddressList = new ArrayList<>();
219+
ccAddressList.add(ccEmailAddress);
220+
221+
ArrayList<EmailAddress> bccAddressList = new ArrayList<>();
222+
bccAddressList.add(bccEmailAddress);
223+
224+
EmailRecipients emailRecipients = new EmailRecipients(toAddressList)
225+
.setCc(ccAddressList)
226+
.setBcc(bccAddressList);
227+
```
228+
229+
You can download the sample app demonstrating this from [GitHub](https://github.com/Azure-Samples/communication-services-java-quickstarts/tree/main/send-email-advanced/send-email-multiple-recipients)
230+
231+
232+
### Send an email message with attachments
233+
234+
We can add an attachment by defining an EmailAttachment object and adding it to our EmailMessage object. Read the attachment file and encode it using Base64.
235+
236+
```java
237+
File file = new File("<your-attachment-path>");
238+
239+
byte[] fileContent = null;
240+
try {
241+
fileContent = Files.readAllBytes(file.toPath());
242+
} catch (Exception e) {
243+
System.out.println(e);
244+
}
245+
246+
String b64file = Base64.getEncoder().encodeToString(fileContent);
247+
248+
EmailAttachment attachment = new EmailAttachment("<your-attachment-name>", "<your-attachment-file-type>", b64file);
249+
250+
ArrayList<EmailAttachment> attachmentList = new ArrayList<>();
251+
attachmentList.add(attachment);
252+
253+
EmailMessage emailMessage = new EmailMessage("<[email protected]>", content)
254+
.setRecipients(emailRecipients)
255+
.setAttachments(attachmentList);
256+
```
257+
258+
You can download the sample app demonstrating this from [GitHub](https://github.com/Azure-Samples/communication-services-java-quickstarts/tree/main/send-email-advanced/send-email-attachments)

articles/communication-services/quickstarts/email/includes/send-email-js.md

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,13 @@ To get the delivery status of email call GetMessageStatus API with MessageId
155155
}
156156
}
157157
} catch (e) {
158-
console.log(e);
158+
console.log(e);
159159
}
160160
}, 5000);
161161

162162
```
163163

164-
| Status Name | Description |
165-
| --------------------| -----------------------------------------------------------------------------------------------------------------------------------------------------|
166-
| Queued | The email has been placed in the queue for delivery. |
167-
| OutForDelivery | The email is currently en route to its recipient(s). |
168-
| Dropped | The email message was dropped before the delivery could be successfully completed. |
164+
[!INCLUDE [Email Message Status](./email-message-status.md)]
169165

170166
## Run the code
171167

@@ -177,3 +173,72 @@ node ./send-email.js
177173
## Sample code
178174

179175
You can download the sample app from [GitHub](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/send-email)
176+
177+
## Advanced
178+
179+
### Send an email message to multiple recipients
180+
181+
We can define multiple recipients by adding additional EmailAddresses to the EmailRecipients object. These addresses can be added as `To`, `CC`, or `BCC` recipients.
182+
183+
```javascript
184+
const emailMessage = {
185+
sender: "<[email protected]>",
186+
content: {
187+
subject: "Welcome to Azure Communication Service Email.",
188+
plainText: "<This email message is sent from Azure Communication Service Email using JS SDK.>"
189+
},
190+
recipients: {
191+
to: [
192+
{ email: "<[email protected]>" },
193+
{ email: "<[email protected]>" }
194+
],
195+
cc: [
196+
{
197+
email: "<[email protected]>"
198+
}
199+
],
200+
bcc: [
201+
{
202+
email: "<[email protected]>" }
203+
}
204+
],
205+
},
206+
};
207+
```
208+
209+
You can download the sample app demonstrating this from [GitHub](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/send-email-advanced/send-email-multiple-recipients)
210+
211+
212+
### Send an email message with attachments
213+
214+
We can add an attachment by defining an EmailAttachment object and adding it to our EmailMessage object. Read the attachment file and encode it using Base64.
215+
216+
```javascript
217+
const fs = require("fs");
218+
219+
const attachmentContent = fs.readFileSync(<your-attachment-path>).toString("base64");
220+
221+
const attachment = {
222+
name: "<your-attachment-name>",
223+
attachmentType: "<your-attachment-type>",
224+
contentBytesBase64: attachmentContent,
225+
}
226+
227+
const emailMessage = {
228+
sender: "<[email protected]>",
229+
content: {
230+
subject: "Welcome to Azure Communication Service Email.",
231+
plainText: "<This email message is sent from Azure Communication Service Email using JS SDK.>"
232+
},
233+
recipients: {
234+
to: [
235+
{
236+
email: "<[email protected]>",
237+
},
238+
],
239+
},
240+
attachments: [attachment]
241+
};
242+
```
243+
244+
You can download the sample app demonstrating this from [GitHub](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/send-email-advanced/send-email-attachments)

articles/communication-services/quickstarts/email/includes/send-email-net.md

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,7 @@ do
175175
} while (DateTime.Now.Ticks - start < duration.Ticks);
176176
```
177177

178-
| Status Name | Description |
179-
| --------------------| -----------------------------------------------------------------------------------------------------------------------------------------------------|
180-
| None | An email with this messageId couldn't be found. |
181-
| Queued | The email has been placed in the queue for delivery. |
182-
| OutForDelivery | The email is currently en route to its recipient(s). |
183-
| InternalError | An error occurred internally during the delivery of this message. Please try again. |
184-
| Dropped | The email message was dropped before the delivery could be successfully completed. |
185-
| InvalidEmailAddress | The sender and/or recipient email address(es) is/are not valid. |
186-
| InvalidAttachments | The content bytes string for the attachment isn't valid. |
187-
| InvalidSenderDomain | The sender's email address domain isn't valid. |
178+
[!INCLUDE [Email Message Status](./email-message-status.md)]
188179

189180
## Run the code
190181

@@ -197,3 +188,51 @@ dotnet run
197188

198189

199190
You can download the sample app from [GitHub](https://github.com/Azure-Samples/communication-services-dotnet-quickstarts/tree/main/SendEmail)
191+
192+
## Advanced
193+
194+
### Send an email message to multiple recipients
195+
196+
We can define multiple recipients by adding additional EmailAddresses to the EmailRecipients object. These addresses can be added as `To`, `CC`, or `BCC` recipients.
197+
198+
```csharp
199+
var toRecipients = new List<EmailAddress>
200+
{
201+
new EmailAddress("<[email protected]>"),
202+
new EmailAddress("<[email protected]>"),
203+
};
204+
205+
var ccRecipients = new List<EmailAddress>
206+
{
207+
new EmailAddress("<[email protected]>"),
208+
};
209+
210+
var bccRecipients = new List<EmailAddress>
211+
{
212+
new EmailAddress("<[email protected]>"),
213+
};
214+
215+
EmailRecipient emailRecipients = new EmailRecipients(toRecipients, ccRecipients, bccRecipients);
216+
```
217+
218+
You can download the sample app demonstrating this from [GitHub](https://github.com/Azure-Samples/communication-services-dotnet-quickstarts/tree/main/SendEmailAdvanced/SendEmailToMultipleRecipients)
219+
220+
221+
### Send an email message with attachments
222+
223+
We can add an attachment by defining an EmailAttachment object and adding it to our EmailMessage object. Read the attachment file and encode it using Base64.
224+
225+
```csharp
226+
byte[] bytes = File.ReadAllBytes(filePath);
227+
string attachmentFileInBytes = Convert.ToBase64String(bytes);
228+
229+
var emailAttachment = new EmailAttachment(
230+
"<your-attachment-name>",
231+
"<your-attachment-name>",
232+
attachmentFileInBytes
233+
);
234+
235+
emailMessage.Add(emailAttachment);
236+
```
237+
238+
You can download the sample app demonstrating this from [GitHub](https://github.com/Azure-Samples/communication-services-dotnet-quickstarts/tree/main/SendEmailAdvanced/SendEmailWithAttachments)

articles/communication-services/quickstarts/email/includes/send-email-python.md

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,7 @@ while True:
152152
break
153153
```
154154

155-
| Status Name | Description |
156-
| ----------- | ------------|
157-
| Queued | The email has been placed in the queue for delivery. |
158-
| OutForDelivery | The email is currently en route to its recipient(s). |
159-
| Dropped | The email message was dropped before the delivery could be successfully completed. |
155+
[!INCLUDE [Email Message Status](./email-message-status.md)]
160156

161157
## Run the code
162158

@@ -169,3 +165,49 @@ python send-email.py
169165
## Sample code
170166

171167
You can download the sample app from [GitHub](https://github.com/Azure-Samples/communication-services-python-quickstarts/tree/main/send-email)
168+
169+
## Advanced
170+
171+
### Send an email message to multiple recipients
172+
173+
We can define multiple recipients by adding additional EmailAddresses to the EmailRecipients object. These addresses can be added as `To`, `CC`, or `BCC` recipients.
174+
175+
```python
176+
to_address_1 = EmailAddress(email="<[email protected]>")
177+
to_address_2 = EmailAddress(email="<[email protected]>")
178+
cc_address = EmailAddress(email="<[email protected]>")
179+
bcc_address = EmailAddress(email="<[email protected]>")
180+
181+
recipient = EmailRecipients(to=[to_address_1, to_address_2], cc=[cc_address], bcc=[bcc_address])
182+
```
183+
184+
You can download the sample app demonstrating this from [GitHub](https://github.com/Azure-Samples/communication-services-python-quickstarts/tree/main/send-email-advanced/send-email-multiple-recipients)
185+
186+
187+
### Send an email message with attachments
188+
189+
We can add an attachment by defining an EmailAttachment object and adding it to our EmailMessage object. Read the attachment file and encode it using Base64. Decode the bytes as a string and pass it into the EmailAttachment object.
190+
191+
```python
192+
import base64
193+
194+
with open("<your-attachment-path>", "rb") as file:
195+
file_bytes = file.read()
196+
197+
file_bytes_b64 = base64.b64encode(file_bytes)
198+
199+
attachment = EmailAttachment(
200+
name="<your-attachment-name>",
201+
attachment_type="<your-attachment-file-type>",
202+
content_bytes_base64=file_bytes_b64.decode()
203+
)
204+
205+
message = EmailMessage(
206+
sender="<[email protected]>",
207+
content=content,
208+
recipients=recipients,
209+
attachments=[attachment]
210+
)
211+
```
212+
213+
You can download the sample app demonstrating this from [GitHub](https://github.com/Azure-Samples/communication-services-python-quickstarts/tree/main/send-email-advanced/send-email-attachments)

articles/communication-services/quickstarts/email/send-email.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ms.date: 04/15/2022
1010
ms.topic: quickstart
1111
ms.service: azure-communication-services
1212
ms.custom: private_preview, event-tier1-build-2022
13-
zone_pivot_groups: acs-js-csharp
13+
zone_pivot_groups: acs-js-csharp-java-python
1414
---
1515

1616
# Quickstart: How to send an email using Azure Communication Service
@@ -24,7 +24,15 @@ In this quick start, you'll learn about how to send email using our Email SDKs.
2424
::: zone-end
2525

2626
::: zone pivot="programming-language-javascript"
27-
[!INCLUDE [Send Email with JavaScript client library](./includes/send-email-js.md)]
27+
[!INCLUDE [Send Email with JavaScript SDK](./includes/send-email-js.md)]
28+
::: zone-end
29+
30+
::: zone pivot="programming-language-java"
31+
[!INCLUDE [Send email with Java SDK](./includes/send-email-java.md)]
32+
::: zone-end
33+
34+
::: zone pivot="programming-language-python"
35+
[!INCLUDE [Send Email with Python SDK](./includes/send-email-python.md)]
2836
::: zone-end
2937

3038
## Troubleshooting

0 commit comments

Comments
 (0)