title | description | author | ms.localizationpriority | ms.subservice | doc_type |
---|---|---|---|---|---|
Add attachment |
Use this API to add an attachment to a message. |
SuryaLashmiS |
medium |
outlook |
apiPageType |
Namespace: microsoft.graph
Use this API to add an attachment to a message.
An attachment can be one of the following types:
- A file (fileAttachment resource).
- An item (contact, event or message, represented by an itemAttachment resource).
- A link to a file (referenceAttachment resource).
All these types of attachment resources are derived from the attachment resource.
You can add an attachment to an existing message by posting to its attachments collection, or you can add an attachment to a message that is being created and sent on the fly.
This operation limits the size of the attachment you can add to under 3 MB.
[!INCLUDE national-cloud-support]
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
[!INCLUDE permissions-table]
Attachments for a message in a user's mailbox.
POST /me/messages/{id}/attachments
POST /users/{id | userPrincipalName}/messages/{id}/attachments
Attachments for a message contained in a top level mailFolder in a user's mailbox.
POST /me/mailFolders/{id}/messages/{id}/attachments
POST /users/{id | userPrincipalName}/mailFolders/{id}/messages/{id}/attachments
Attachments for a message contained in a child folder of a mailFolder in a user's mailbox. The example below shows one level of nesting, but a message can be located in a child of a child and so on.
POST /me/mailFolders/{id}/childFolders/{id}/.../messages/{id}/attachments/{id}
POST /users/{id | userPrincipalName}/mailFolders/{id}/childFolders/{id}/messages/{id}/attachments/{id}
Name | Type | Description |
---|---|---|
Authorization | string | Bearer {token}. Required. Learn more about authentication and authorization. |
Content-Type | string | Nature of the data in the body of an entity. Required. |
In the request body, supply a JSON representation of Attachment object.
If successful, this method returns 201 Created
response code and Attachment object in the response body.
The following example shows a request.
POST https://graph.microsoft.com/v1.0/me/messages/AAMkpsDRVK/attachments
Content-type: application/json
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "smile",
"contentBytes": "R0lGODdhEAYEAA7"
}
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
In the request body, supply a JSON representation of attachment object.
The following example shows the response.
HTTP 201 Created
Content-type: application/json
{
"id": "AAMkADNkN2R",
"lastModifiedDateTime": "2017-01-26T08:48:28Z",
"name": "smile",
"contentType": "image/gif",
"size": 1008,
"isInline": false,
"contentId": null,
"contentLocation": null,
"contentBytes": "R0lGODdhEAYEAA7"
}
The following example shows a request.
POST https://graph.microsoft.com/v1.0/me/messages/AAMkpsDRVK/attachments
Content-type: application/json
{
"@odata.type": "#microsoft.graph.itemAttachment",
"name": "Holiday event",
"item": {
"@odata.type": "microsoft.graph.event",
"subject": "Discuss gifts for children",
"body": {
"contentType": "HTML",
"content": "Let's look for funding!"
},
"start": {
"dateTime": "2016-12-02T18:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2016-12-02T19:00:00",
"timeZone": "Pacific Standard Time"
}
}
}
The following example shows the response. Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 Created
Content-type: application/json
{
"id":"AAMkADNkNJp5JVnQIe9r0=",
"lastModifiedDateTime":"2016-12-01T22:27:13Z",
"name":"Holiday event",
"contentType":null,
"size":2473,
"isInline":false
}