Skip to content

Commit 382daf7

Browse files
Merge pull request #232053 from natekimball-msft/natekimball/add-mime-attachment-type-doc
Adding MIME type document and bugbash updates
2 parents 1bd00ef + a8d63b3 commit 382daf7

File tree

5 files changed

+210
-31
lines changed

5 files changed

+210
-31
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: Allowed attachment types for sending email
3+
titleSuffix: An Azure Communication Services concept document
4+
description: Learn about how validation for attachment MIME types works for Email Communication Services.
5+
author: natekimball-msft
6+
manager: koagbakp
7+
services: azure-communication-services
8+
ms.author: natekimball
9+
ms.date: 03/24/2023
10+
ms.topic: conceptual
11+
ms.service: azure-communication-services
12+
ms.custom: private_preview, event-tier1-build-2022
13+
---
14+
15+
# Allowed attachment types for sending email in Azure Communication Services Email
16+
17+
The [Send Email operation](../../quickstarts/email/send-email.md) allows the option for the sender to add attachments to an outgoing email. Along with the content itself, the sender must include the file attachment type using the MIME standard when making a request with an attachment. Many common file types are accepted, such as Word documents, Excel spreadsheets, many image and video formats, contacts, and calendar invites.
18+
19+
## What is a MIME type?
20+
21+
MIME (Multipurpose Internet Mail Extensions) types are a way of identifying the type of data that is being sent over the internet. When users send email requests with Azure Communication Services Email, they can specify the MIME type of the email content, which allows the recipient's email client to properly display and interpret the message. If an email message includes an attachment, the MIME type would be set to the appropriate file type (for example, "application/pdf" for a PDF document).
22+
23+
Developers can ensure that the recipient's email client properly formats and interprets the email message by using MIME types, irrespective of the software or platform being used. This information helps to ensure that the email message is delivered correctly and that the recipient can access the content as intended. In addition, using MIME types can also help to improve the security of email communications, as they can be used to indicate whether an email message includes executable content or other potentially harmful elements.
24+
25+
To sum up, MIME types are a critical component of email communication, and by using them with Azure Communication Services Email, developers can help ensure that their email messages are delivered correctly and securely.
26+
27+
## Allowed attachment types
28+
29+
Here's a table listing some of the most common supported file extensions and their corresponding MIME types for email attachments using Azure Communication Services Email:
30+
31+
| File Extension | Description | MIME Type |
32+
| --- | --- | --- |
33+
| .3gp | 3GPP multimedia file | `video/3gpp` |
34+
| .3g2 | 3GPP2 multimedia file | `video/3gpp2` |
35+
| .7z | 7-Zip compressed file | `application/x-7z-compressed` |
36+
| .aac | AAC audio | `audio/aac` |
37+
| .avi | AVI video file | `video/x-msvideo` |
38+
| .bmp | BMP image | `image/bmp` |
39+
| .csv | Comma-separated values | `text/csv` |
40+
| .doc | Microsoft Word document (97-2003) | `application/msword` |
41+
| .docm | Microsoft Word macro-enabled document | `application/vnd.ms-word.document.macroEnabled.12` |
42+
| .docx | Microsoft Word document (2007 or later) | `application/vnd.openxmlformats-officedocument.wordprocessingml.document` |
43+
| .eot | Embedded OpenType font | `application/vnd.ms-fontobject` |
44+
| .epub | EPUB ebook file | `application/epub+zip` |
45+
| .gif | GIF image | `image/gif` |
46+
| .gz | Gzip compressed file | `application/gzip` |
47+
| .ico | Icon file | `image/vnd.microsoft.icon` |
48+
| .ics | iCalendar file | `text/calendar` |
49+
| .jpg, .jpeg | JPEG image | `image/jpeg` |
50+
| .json | JSON data | `application/json` |
51+
| .mid, .midi | MIDI audio file | `audio/midi` |
52+
| .mp3 | MP3 audio file | `audio/mpeg` |
53+
| .mp4 | MP4 video file | `video/mp4` |
54+
| .mpeg | MPEG video file | `video/mpeg` |
55+
| .oga | Ogg audio file | `audio/ogg` |
56+
| .ogv | Ogg video file | `video/ogg` |
57+
| .ogx | Ogg file | `application/ogg` |
58+
| .one | Microsoft OneNote file | `application/onenote` |
59+
| .opus | Opus audio file | `audio/opus` |
60+
| .otf | OpenType font | `font/otf` |
61+
| .pdf | PDF document | `application/pdf` |
62+
| .png | PNG image | `image/png` |
63+
| .ppsm | PowerPoint slideshow (macro-enabled) | `application/vnd.ms-powerpoint.slideshow.macroEnabled.12` |
64+
| .ppsx | PowerPoint slideshow | `application/vnd.openxmlformats-officedocument.presentationml.slideshow` |
65+
| .ppt | PowerPoint presentation (97-2003) | `application/vnd.ms-powerpoint` |
66+
| .pptm | PowerPoint macro-enabled presentation | `application/vnd.ms-powerpoint.presentation.macroEnabled.12` |
67+
| .pptx | PowerPoint presentation (2007 or later) | `application/vnd.openxmlformats-officedocument.presentationml.presentation` |
68+
| .pub | Microsoft Publisher document | `application/vnd.ms-publisher` |
69+
| .rar | RAR compressed file | `application/x-rar-compressed` |
70+
| .rpmsg | Outlook email message | `application/vnd.ms-outlook` |
71+
| .rtf | Rich Text Format document | `application/rtf` |
72+
| .svg | Scalable Vector Graphics image | `image/svg+xml` |
73+
| .tar | Tar archive file | `application/x-tar` |
74+
| .tif, .tiff | Tagged Image File Format | `image/tiff` |
75+
| .ttf | TrueType Font | `font/ttf` |
76+
| .txt | Text Document | `text/plain` |
77+
| .vsd | Microsoft Visio Drawing | `application/vnd.visio` |
78+
| .wav | Waveform Audio File Format | `audio/wav` |
79+
| .weba | WebM Audio File | `audio/webm` |
80+
| .webm | WebM Video File | `video/webm` |
81+
| .webp | WebP Image File | `image/webp` |
82+
| .wma | Windows Media Audio File | `audio/x-ms-wma` |
83+
| .wmv | Windows Media Video File | `video/x-ms-wmv` |
84+
| .woff | Web Open Font Format | `font/woff` |
85+
| .woff2 | Web Open Font Format 2.0 | `font/woff2` |
86+
| .xls | Microsoft Excel Spreadsheet (97-2003) | `application/vnd.ms-excel` |
87+
| .xlsb | Microsoft Excel Binary Spreadsheet | `application/vnd.ms-excel.sheet.binary.macroEnabled.12` |
88+
| .xlsm | Microsoft Excel Macro-Enabled Spreadsheet | `application/vnd.ms-excel.sheet.macroEnabled.12` |
89+
| .xlsx | Microsoft Excel Spreadsheet (OpenXML) | `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` |
90+
| .xml | Extensible Markup Language File | `application/xml`, `text/xml` |
91+
| .zip | ZIP Archive | `application/zip` |
92+
93+
There are many other file extensions and MIME types that can be used for email attachments. However, this list includes accepted types for sending attachments in our SendMail operation. Additionally, different email clients and servers may have different limitations or restrictions on file size and types that could result in the failure of email delivery. Ensure that the recipient can accept the email attachment or refer to the documentation for the recipient's email providers.
94+
95+
## Additional information
96+
97+
The Internet Assigned Numbers Authority (IANA) is a department of the Internet Corporation for Assigned Names and Numbers (ICANN) responsible for the global coordination of various Internet protocols and resources, including the management and registration of MIME types.
98+
99+
The IANA maintains a registry of standardized MIME types, which includes a unique identifier for each MIME type, a short description of its purpose, and the associated file extensions. For the most up-to-date information regarding MIME types, including the definitive list of media types, it's recommended to visit the [IANA Website](https://www.iana.org/assignments/media-types/media-types.xhtml) directly.
100+
101+
## Next steps
102+
103+
* [What is Email Communication Communication Service](./prepare-email-communication-resource.md)
104+
105+
* [Email domains and sender authentication for Azure Communication Services](./email-domain-and-sender-authentication.md)
106+
107+
* [Get started with sending email using Email Communication Service in Azure Communication Service](../../quickstarts/email/send-email.md)
108+
109+
* [Get started by connecting Email Communication Service with a Azure Communication Service resource](../../quickstarts/email/connect-email-communication-resource.md)
110+
111+
The following documents may be interesting to you:
112+
113+
- Familiarize yourself with the [Email client library](../email/sdk-features.md)
114+
- How to send emails with custom verified domains? [Add custom domains](../../quickstarts/email/add-custom-verified-domains.md)
115+
- How to send emails with Azure Managed Domains? [Add Azure Managed domains](../../quickstarts/email/add-azure-managed-domains.md)

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

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: natekimball-msft
55
manager: koagbakp
66
services: azure-communication-services
77
ms.author: natekimball
8-
ms.date: 03/03/2023
8+
ms.date: 03/24/2023
99
ms.topic: include
1010
ms.service: azure-communication-services
1111
ms.custom: mode-other
@@ -20,7 +20,7 @@ The following classes and interfaces handle some of the major features of the Az
2020
| Name | Description |
2121
| ---- |-------------|
2222
| EmailAddress | This class contains an email address and an option for a display name. |
23-
| EmailAttachment | This interface creates an email attachment by accepting a unique ID, email attachment type, and a string of content bytes. |
23+
| 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. |
2424
| EmailClient | This class is needed for all email functionality. You instantiate it with your connection string and use it to send email messages. |
2525
| EmailMessage | This class combines the sender, content, and recipients. Custom headers, attachments, and reply-to email addresses can optionally be added, as well. |
2626
| EmailSendResult | This class holds the results of the email send operation. It has an operation ID, operation status and error object (when applicable). |
@@ -119,7 +119,7 @@ EmailClient emailClient = new EmailClientBuilder()
119119

120120
### Option 2: Authenticate using Azure Active Directory
121121

122-
A `DefaultAzureCredential` object must be passed to the `EmailClientBuilder` via the `credential()` method. An endpoint must also be set via the `endpoint()` method.
122+
A [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/identity/azure-identity#defaultazurecredential) object must be passed to the `EmailClientBuilder` via the `credential()` method. An endpoint must also be set via the `endpoint()` method.
123123

124124
The `AZURE_CLIENT_SECRET`, `AZURE_CLIENT_ID`, and `AZURE_TENANT_ID` environment variables are needed to create a `DefaultAzureCredential` object.
125125

@@ -158,10 +158,43 @@ EmailMessage message = new EmailMessage()
158158
.setSubject("Welcome to Azure Communication Services Email")
159159
.setBodyPlainText("This email message is sent from Azure Communication Services Email using the Java SDK.");
160160

161-
SyncPoller<EmailSendResult, EmailSendResult> poller = emailClient.beginSend(message, null);
162-
PollResponse<EmailSendResult> response = poller.waitForCompletion();
163-
164-
System.out.println("Operation Id: " + response.getValue().getId());
161+
try
162+
{
163+
SyncPoller<EmailSendResult, EmailSendResult> poller = emailClient.beginSend(message, null);
164+
165+
PollResponse<EmailSendResult> pollResponse = null;
166+
167+
Duration timeElapsed = Duration.ofSeconds(0);
168+
169+
while (pollResponse == null
170+
|| pollResponse.getStatus() == LongRunningOperationStatus.NOT_STARTED
171+
|| pollResponse.getStatus() == LongRunningOperationStatus.IN_PROGRESS)
172+
{
173+
pollResponse = poller.poll();
174+
System.out.println("Email send poller status: " + pollResponse.getStatus());
175+
176+
Thread.sleep(POLLER_WAIT_TIME.toMillis());
177+
timeElapsed = timeElapsed.plus(POLLER_WAIT_TIME);
178+
179+
if (timeElapsed.compareTo(POLLER_WAIT_TIME.multipliedBy(18)) >= 0)
180+
{
181+
throw new RuntimeException("Polling timed out.");
182+
}
183+
}
184+
185+
if (poller.getFinalResult().getStatus() == EmailSendStatus.SUCCEEDED)
186+
{
187+
System.out.printf("Successfully sent the email (operation id: %s)", poller.getFinalResult().getId());
188+
}
189+
else
190+
{
191+
throw new RuntimeException(poller.getFinalResult().getError().getMessage());
192+
}
193+
}
194+
catch (Exception exception)
195+
{
196+
System.out.println(exception.getMessage());
197+
}
165198
```
166199

167200
Make these replacements in the code:
@@ -227,15 +260,17 @@ EmailMessage message = new EmailMessage()
227260
.setSenderAddress("<[email protected]>")
228261
.setSubject("Welcome to Azure Communication Services Email")
229262
.setBodyPlainText("This email message is sent from Azure Communication Services Email using the Java SDK.")
230-
.setToRecipients(toAddress1, toAddress2);
263+
.setToRecipients(toAddress1, toAddress2)
264+
.setCcRecipients(toAddress1, toAddress2)
265+
.setBccRecipients(toAddress1, toAddress2)
231266

232267
SyncPoller<EmailSendResult, EmailSendResult> poller = emailClient.beginSend(message, null);
233268
PollResponse<EmailSendResult> response = poller.waitForCompletion();
234269

235270
System.out.println("Operation Id: " + response.getValue().getId());
236271
```
237272

238-
You can download the sample app demonstrating this action from [GitHub](https://github.com/Azure-Samples/communication-services-java-quickstarts/tree/main/send-email)
273+
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)
239274

240275
### Send an email message with attachments
241276

@@ -262,4 +297,6 @@ PollResponse<EmailSendResult> response = poller.waitForCompletion();
262297
System.out.println("Operation Id: " + response.getValue().getId());
263298
```
264299

265-
You can download the sample app demonstrating this action from [GitHub](https://github.com/Azure-Samples/communication-services-java-quickstarts/tree/main/send-email)
300+
For more information on acceptable MIME types for email attachments, see the [allowed MIME types](../../../concepts/email/email-attachment-allowed-mime-types.md) documentation.
301+
302+
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)

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: natekimball-msft
55
manager: koagbakp
66
services: azure-communication-services
77
ms.author: natekimball
8-
ms.date: 04/15/2022
8+
ms.date: 03/24/2023
99
ms.topic: include
1010
ms.service: azure-communication-services
1111
ms.custom: mode-other
@@ -20,7 +20,7 @@ The following classes and interfaces handle some of the major features of the Az
2020
| Name | Description |
2121
| ---- |-------------|
2222
| EmailAddress | This class contains an email address and an option for a display name. |
23-
| EmailAttachment | This class creates an email attachment by accepting a unique ID, email attachment mime type string, and binary data for content. |
23+
| 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. |
2424
| EmailClient | This class is needed for all email functionality. You instantiate it with your connection string and use it to send email messages. |
2525
| EmailClientOptions | This class can be added to the EmailClient instantiation to target a specific API version. |
2626
| 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. |
@@ -172,7 +172,30 @@ async function main() {
172172
};
173173

174174
const poller = await emailClient.beginSend(message);
175-
const response = await poller.pollUntilDone();
175+
176+
if (!poller.getOperationState().isStarted) {
177+
throw "Poller was not started."
178+
}
179+
180+
let timeElapsed = 0;
181+
while(!poller.isDone()) {
182+
poller.poll();
183+
console.log("Email send polling in progress");
184+
185+
await new Promise(resolve => setTimeout(resolve, POLLER_WAIT_TIME * 1000));
186+
timeElapsed += 10;
187+
188+
if(timeElapsed > 18 * POLLER_WAIT_TIME) {
189+
throw "Polling timed out.";
190+
}
191+
}
192+
193+
if(poller.getResult().status === KnownEmailSendStatus.Succeeded) {
194+
console.log(`Successfully sent the email (operation id: ${poller.getResult().id})`);
195+
}
196+
else {
197+
throw poller.getResult().error;
198+
}
176199
} catch (e) {
177200
console.log(e);
178201
}
@@ -273,7 +296,7 @@ const message = {
273296
attachments: [
274297
{
275298
name: path.basename(filePath),
276-
contentType: "text/plain",
299+
contentType: "<mime-type-for-your-file>",
277300
contentInBase64: readFileSync(filePath, "base64"),
278301
}
279302
]
@@ -282,4 +305,6 @@ const message = {
282305
const response = await emailClient.send(message);
283306
```
284307

308+
For more information on acceptable MIME types for email attachments, see the [allowed MIME types](../../../concepts/email/email-attachment-allowed-mime-types.md) documentation.
309+
285310
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-attachments)

0 commit comments

Comments
 (0)