Skip to content

Commit c9ca40f

Browse files
Merge pull request #286673 from natekimball-msft/natekimball/update-documentation-for-inline-attachments
Add section in advanced sending for inline images
2 parents 830d979 + 5320b4b commit c9ca40f

14 files changed

+440
-78
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The following classes and interfaces handle some of the major features of the Az
2323
| Name | Description |
2424
| --------------------| -----------------------------------------------------------------------------------------------------------------------------------------------------|
2525
| EmailAddress | This class contains an email address and an option for a display name. |
26-
| EmailAttachment | This class creates an email attachment by accepting a unique ID, email attachment [MIME type](../../../concepts/email/email-attachment-allowed-mime-types.md) string, and binary data for content. |
26+
| EmailAttachment | This class creates an email attachment by accepting a unique ID, email attachment [MIME type](../../../concepts/email/email-attachment-allowed-mime-types.md) string, binary data for content, and an optional content ID to define it as an inline attachment. |
2727
| EmailClient | This class is needed for all email functionality. You instantiate it with your connection string and use it to send email messages. |
2828
| EmailClientOptions | This class can be added to the EmailClient instantiation to target a specific API version. |
2929
| EmailContent | This class contains the subject and the body of the email message. You have to specify at least one of PlainText or Html content |
@@ -46,7 +46,7 @@ EmailSendResult returns the following status on the email operation performed.
4646

4747
## Prerequisites
4848

49-
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
49+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
5050
- The latest version [.NET Core client library](https://dotnet.microsoft.com/download/dotnet-core) for your operating system.
5151
- An Azure Email Communication Services Resource created and ready with a provisioned domain [Get started with Creating Email Communication Resource](../create-email-communication-resource.md)
5252
- An active Communication Services resource connected with Email Domain and a Connection String. [Get started by Connecting Email Resource with a Communication Resource](../connect-email-communication-resource.md)
@@ -160,13 +160,13 @@ var emailClient = new EmailClient(endpoint, key);
160160

161161
#### [Send Email with synchronous status polling](#tab/send-smail-and-get-status-sync)
162162

163-
## Basic email sending
163+
## Basic email sending
164164

165165
### Construct your email message
166166

167167
To send an email message, you need to:
168168
- Define the email subject and body.
169-
- Define your Sender Address. Construct your email message with your Sender information you get your MailFrom address from your verified domain.
169+
- Define your Sender Address. Construct your email message with your Sender information you get your MailFrom address from your verified domain.
170170
- Define the Recipient Address.
171171
- Call the SendAsync method. Add this code to the end of `Main` method in **Program.cs**:
172172

@@ -184,7 +184,7 @@ var recipient = "[email protected]";
184184
### Send and get the email send status
185185

186186
To send an email message, you need to:
187-
- Call SendAsync method that sends the email request as an asynchronous operation. Call with Azure.WaitUntil.Completed if your method should wait to return until the long-running operation has completed on the service. Call with Azure.WaitUntil.Started if your method should return after starting the operation.
187+
- Call SendAsync method that sends the email request as an asynchronous operation. Call with Azure.WaitUntil.Completed if your method should wait to return until the long-running operation has completed on the service. Call with Azure.WaitUntil.Started if your method should return after starting the operation.
188188
- SendAsync method returns EmailSendOperation that returns "Succeeded" EmailSendStatus if email is out for delivery and throws an exception otherwise. Add this code to the end of `Main` method in **Program.cs**:
189189

190190
```csharp
@@ -198,7 +198,7 @@ try
198198
subject,
199199
htmlContent);
200200
EmailSendResult statusMonitor = emailSendOperation.Value;
201-
201+
202202
Console.WriteLine($"Email Sent. Status = {emailSendOperation.Value.Status}");
203203

204204
/// Get the OperationId so that it can be used for tracking the message for troubleshooting
@@ -216,8 +216,8 @@ catch (RequestFailedException ex)
216216

217217
EmailSendOperation only returns email operation status. To get the actual email delivery status, you can subscribe to "EmailDeliveryReportReceived" event that is generated when the email delivery is completed. The event returns the following delivery state:
218218

219-
- Delivered.
220-
- Failed.
219+
- Delivered.
220+
- Failed.
221221
- Quarantined.
222222

223223
See [Handle Email Events](../handle-email-events.md) for details.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The following classes and interfaces handle some of the major features of the Az
2323
| Name | Description |
2424
| ---- |-------------|
2525
| EmailAddress | This class contains an email address and an option for a display name. |
26-
| EmailAttachment | This interface creates an email attachment by accepting a unique ID, email attachment [MIME type](../../../concepts/email/email-attachment-allowed-mime-types.md) string, and a string of content bytes. |
26+
| EmailAttachment | This interface creates an email attachment by accepting a unique ID, email attachment [MIME type](../../../concepts/email/email-attachment-allowed-mime-types.md) string, a string of content bytes, and an optional content ID to define it as an inline attachment. |
2727
| EmailClient | This class is needed for all email functionality. You instantiate it with your connection string and use it to send email messages. |
2828
| EmailMessage | This class combines the sender, content, and recipients. Custom headers, attachments, and reply-to email addresses can optionally be added, as well. |
2929
| EmailSendResult | This class holds the results of the email send operation. It has an operation ID, operation status and error object (when applicable). |
@@ -193,7 +193,7 @@ For simplicity, this quickstart uses connection strings, but in production envir
193193

194194

195195

196-
## Basic email sending
196+
## Basic email sending
197197

198198
An email message can be crafted using the `EmailMessage` object in the SDK.
199199

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The following classes and interfaces handle some of the major features of the Az
2323
| Name | Description |
2424
| ---- |-------------|
2525
| EmailAddress | This class contains an email address and an option for a display name. |
26-
| EmailAttachment | This class creates an email attachment by accepting a unique ID, email attachment [MIME type](../../../concepts/email/email-attachment-allowed-mime-types.md) string, and binary data for content. |
26+
| EmailAttachment | This class creates an email attachment by accepting a unique ID, email attachment [MIME type](../../../concepts/email/email-attachment-allowed-mime-types.md) string, binary data for content, and an optional Content ID to define it as an inline attachment. |
2727
| EmailClient | This class is needed for all email functionality. You instantiate it with your connection string and use it to send email messages. |
2828
| EmailClientOptions | This class can be added to the EmailClient instantiation to target a specific API version. |
2929
| EmailContent | This class contains the subject and the body of the email message. You have to specify at least one of PlainText or Html content. |
@@ -153,7 +153,7 @@ const emailClient = new EmailClient(endpoint, key);
153153

154154
For simplicity, this quickstart uses connection strings, but in production environments, we recommend using [service principals](../../../quickstarts/identity/service-principal.md).
155155

156-
## Basic email sending
156+
## Basic email sending
157157

158158
### Send an email message
159159

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The following classes and interfaces handle some of the major features of the Az
2323
| Name | Description |
2424
| --------------------| -----------------------------------------------------------------------------------------------------------------------------------------------------|
2525
| EmailAddress | This class contains an email address and an option for a display name. |
26-
| EmailAttachment | This class creates an email attachment by accepting a unique ID, email attachment [MIME type](../../../concepts/email/email-attachment-allowed-mime-types.md) string, and binary data for content. |
26+
| EmailAttachment | This class creates an email attachment by accepting a unique ID, email attachment [MIME type](../../../concepts/email/email-attachment-allowed-mime-types.md) string, binary data for content, and an optional content ID to define it as an inline attachment. |
2727
| EmailClient | This class is needed for all email functionality. You instantiate it with your connection string and use it to send email messages. |
2828
| EmailClientOptions | This class can be added to the EmailClient instantiation to target a specific API version. |
2929
| EmailContent | This class contains the subject and the body of the email message. You have to specify at least one of PlainText or Html content |
@@ -46,7 +46,7 @@ EmailSendResult returns the following status on the email operation performed.
4646

4747
## Prerequisites
4848

49-
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
49+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
5050
- The latest version [.NET Core client library](https://dotnet.microsoft.com/download/dotnet-core) for your operating system.
5151
- An Azure Email Communication Services Resource created and ready with a provisioned domain [Get started with Creating Email Communication Resource](../create-email-communication-resource.md)
5252
- An active Communication Services resource connected with Email Domain and a Connection String. [Get started by Connecting Email Resource with a Communication Resource](../connect-email-communication-resource.md)
@@ -151,13 +151,13 @@ var emailClient = new EmailClient(endpoint, key);
151151

152152
---
153153

154-
## Basic email sending
154+
## Basic email sending
155155

156156
### Construct your email message
157157

158158
To send an email message, you need to:
159159
- Define the email subject and body.
160-
- Define your Sender Address. Construct your email message with your Sender information you get your MailFrom address from your verified domain.
160+
- Define your Sender Address. Construct your email message with your Sender information you get your MailFrom address from your verified domain.
161161
- Define the Recipient Address.
162162
- Call the SendAsync method. Add this code to the end of `Main` method in **Program.cs**:
163163

@@ -175,7 +175,7 @@ var recipient = "[email protected]";
175175
### Send and get the email send status
176176

177177
To send an email message, you need to:
178-
- Call SendAsync method that sends the email request as an asynchronous operation. Call with Azure.WaitUntil.Completed if your method should wait to return until the long-running operation has completed on the service. Call with Azure.WaitUntil.Started if your method should return after starting the operation.
178+
- Call SendAsync method that sends the email request as an asynchronous operation. Call with Azure.WaitUntil.Completed if your method should wait to return until the long-running operation has completed on the service. Call with Azure.WaitUntil.Started if your method should return after starting the operation.
179179
- SendAsync method returns EmailSendOperation that returns "Succeeded" EmailSendStatus if email is out for delivery and throws an exception otherwise. Add this code to the end of `Main` method in **Program.cs**:
180180

181181
```csharp
@@ -189,7 +189,7 @@ try
189189
subject,
190190
htmlContent);
191191
EmailSendResult statusMonitor = emailSendOperation.Value;
192-
192+
193193
Console.WriteLine($"Email Sent. Status = {emailSendOperation.Value.Status}");
194194

195195
/// Get the OperationId so that it can be used for tracking the message for troubleshooting
@@ -207,8 +207,8 @@ catch (RequestFailedException ex)
207207

208208
EmailSendOperation only returns email operation status. To get the actual email delivery status, you can subscribe to "EmailDeliveryReportReceived" event that is generated when the email delivery is completed. The event returns the following delivery state:
209209

210-
- Delivered.
211-
- Failed.
210+
- Delivered.
211+
- Failed.
212212
- Quarantined.
213213

214214
See [Handle Email Events](../handle-email-events.md) for details.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: include file
3+
description: Inline Attachments Java SDK include file
4+
author: natekimball-msft
5+
manager: koagbakp
6+
services: azure-communication-services
7+
ms.author: natekimball
8+
ms.date: 04/07/2023
9+
ms.topic: include
10+
ms.service: azure-communication-services
11+
---
12+
13+
## Send an email message with inline attachments
14+
15+
We can add an inline attachment by defining one or more EmailAttachment objects, defining a unique `ContentId` for each, and adding them to our EmailMessage object. Read the attachment file and encode it using Base64.
16+
17+
```java
18+
byte[] jpgContent = Files.readAllBytes(new File("./inline-attachment.jpg").toPath());
19+
byte[] jpgEncodedContent = Base64.getEncoder().encodeToString(jpgContent).getBytes();
20+
EmailAttachment jpgInlineAttachment = new EmailAttachment(
21+
"inline-attachment.jpg",
22+
"image/jpeg",
23+
BinaryData.fromBytes(jpgEncodedContent)
24+
).setContentId("my-inline-attachment-1");
25+
26+
byte[] pngContent = Files.readAllBytes(new File("./inline-attachment.png").toPath());
27+
byte[] pngEncodedContent = Base64.getEncoder().encodeToString(pngContent).getBytes();
28+
EmailAttachment pngInlineAttachment = new EmailAttachment(
29+
"inline-attachment.png",
30+
"image/png",
31+
BinaryData.fromBytes(pngEncodedContent)
32+
).setContentId("my-inline-attachment-2");
33+
```
34+
35+
Within the HTML body of the message, we can then embed an image by referencing its `ContentId` within the source of an `<img>` tag.
36+
37+
```java
38+
EmailMessage message = new EmailMessage()
39+
.setSenderAddress(senderAddress)
40+
.setToRecipients(recipientAddress)
41+
.setSubject("Welcome to Azure Communication Services Email")
42+
.setBodyPlainText("This email message is sent from Azure Communication Services Email using the Java SDK.");
43+
.setBodyHtml("<html><h1>HTML body inline images:</h1><img src=\"cid:my-inline-attachment-1\" /><img src=\"cid:my-inline-attachment-2\" /></html>")
44+
.setAttachments(jpgInlineAttachmentContent, pngInlineAttachmentContent);
45+
46+
SyncPoller<EmailSendResult, EmailSendResult> poller = emailClient.beginSend(message, null);
47+
PollResponse<EmailSendResult> response = poller.waitForCompletion();
48+
49+
System.out.println("Operation Id: " + response.getValue().getId());
50+
```
51+
52+
> [!NOTE]
53+
> Regular attachments can be combined with inline attachments, as well. Defining a `ContentId` will treat an attachment as inline, while an attachment without a `ContentId` will be treated as a regular attachment.
54+
55+
### Allowed MIME types
56+
57+
Although most modern clients support inline attachments, the rendering behavior of an inline attachment is largely dependent on the recipient's email client. For this reason, it is suggested to use more common image formats inline whenever possible, such as .png, .jpg, or .gif. For more information on acceptable MIME types for email attachments, see the [allowed MIME types](../../../../concepts/email/email-attachment-allowed-mime-types.md) documentation.
58+
59+
### Sample code
60+
61+
You can download the sample app demonstrating this action from [GitHub](https://github.com/Azure-Samples/communication-services-java-quickstarts/tree/main/send-email-advanced/send-email-inline-attachments)
62+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: include file
3+
description: Inline Attachments JS SDK include file
4+
author: natekimball-msft
5+
manager: koagbakp
6+
services: azure-communication-services
7+
ms.author: natekimball
8+
ms.date: 04/07/2023
9+
ms.topic: include
10+
ms.service: azure-communication-services
11+
---
12+
13+
## Send an email message with inline attachments
14+
15+
We can add an inline attachment by defining one or more attachment objects, making sure to include a unique `contentId` for each, and adding them to our message. Read the attachment file and encode it using Base64.
16+
17+
```javascript
18+
const jpgFilePath = "./inline-attachment.jpg";
19+
const pngFilePath = "./inline-attachment.png";
20+
21+
const inlineAttachments = [
22+
{
23+
name: path.basename(jpgFilePath),
24+
contentId: "my-inline-attachment-1"
25+
contentType: "image/jpeg",
26+
contentInBase64: readFileSync(jpgFilePath, "base64"),
27+
},
28+
{
29+
name: path.basename(pngFilePath),
30+
contentId: "my-inline-attachment-2"
31+
contentType: "image/png",
32+
contentInBase64: readFileSync(pngFilePath, "base64"),
33+
}
34+
];
35+
```
36+
37+
Within the HTML body of the message, we can then embed an image by referencing its `contentId` within the source of an `<img>` tag.
38+
39+
```javascript
40+
const message = {
41+
sender: "<[email protected]>",
42+
content: {
43+
subject: "Welcome to Azure Communication Services Email",
44+
plainText: "This email message is sent from Azure Communication Services Email using the Javascript SDK.",
45+
html: "<html><h1>HTML body inline images:</h1><img src=\"cid:my-inline-attachment-1\" /><img src=\"cid:my-inline-attachment-2\" /></html>"
46+
},
47+
recipients: {
48+
to: [
49+
{
50+
address: "<[email protected]>",
51+
displayName: "Customer Name",
52+
}
53+
]
54+
},
55+
attachments: inlineAttachments
56+
};
57+
58+
const poller = await emailClient.beginSend(message);
59+
const response = await poller.pollUntilDone();
60+
```
61+
62+
> [!NOTE]
63+
> Regular attachments can be combined with inline attachments, as well. Defining a `contentId` will treat an attachment as inline, while an attachment without a `contentId` will be treated as a regular attachment.
64+
65+
### Allowed MIME types
66+
67+
Although most modern clients support inline attachments, the rendering behavior of an inline attachment is largely dependent on the recipient's email client. For this reason, it is suggested to use more common image formats inline whenever possible, such as .png, .jpg, or .gif. For more information on acceptable MIME types for email attachments, see the [allowed MIME types](../../../../concepts/email/email-attachment-allowed-mime-types.md) documentation.
68+
69+
### Sample code
70+
71+
You can download the sample app demonstrating this action from [GitHub](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/send-email-advanced/send-email-inline-attachments)

0 commit comments

Comments
 (0)