This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Download Microsoft Edge
More info about Internet Explorer and Microsoft Edge
Namespace: microsoft.graph
Create a draft of a new
message
in either JSON or MIME format.
When using JSON format, you can:
Include an
attachment
to the
message
.
Update
the draft later to add content to the
body
or change other message properties.
When using MIME format:
Provide the applicable
Internet message headers
and the
MIME content
, all encoded in
base64
format in the request body.
* Add any attachments and S/MIME properties to the MIME content.
By default, this operation saves the draft in the Drafts folder.
Send
the draft message in a subsequent operation.
Alternatively,
send a new message
in a single operation, or create a draft to
forward
,
reply
and
reply-all
to an existing message.
*
Note:
S/MIME message payloads are currently limited to 4 MB. Submission attempts that exceed this limit will result in an
HTTP 413 Request Entity Too Large
error response.
Permissions
One of the following permissions are required to call this API. To learn more, including how to choose permissions, see
Permissions
.
Permission type
Permissions (from least to most privileged)
POST /me/messages
POST /users/{id|userPrincipalName}/messages
POST /me/mailFolders/{id}/messages
POST /users/{id | userPrincipalName}/mailFolders/{id}/messages
Description
Request body
When using JSON format, provide a JSON representation of message object.
When specifying the body in MIME format, provide the MIME content with the applicable Internet message headers ("To", "CC", "BCC", "Subject"), all encoded in base64 format in the request body.
Since the message resource supports extensions, you can use the POST
operation and add custom properties with your own data to the message while creating it.
Response
If successful, this method returns 201 Created
response code and message object in the response body.
If the request body includes malformed MIME content, this method returns 400 Bad request
and the following error message: "Invalid base64 string for MIME content".
Examples
Request
Here is an example of the request.
JavaScript
PowerShell
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Message
Subject = "Did you see last night's game?",
Importance = Importance.Low,
Body = new ItemBody
ContentType = BodyType.Html,
Content = "They were <b>awesome</b>!",
ToRecipients = new List<Recipient>
new Recipient
EmailAddress = new EmailAddress
Address = "AdeleV@contoso.onmicrosoft.com",
var result = await graphClient.Me.Messages.PostAsync(requestBody);
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewMessage()
subject := "Did you see last night's game?"
requestBody.SetSubject(&subject)
importance := graphmodels.LOW_IMPORTANCE
requestBody.SetImportance(&importance)
body := graphmodels.NewItemBody()
contentType := graphmodels.HTML_BODYTYPE
body.SetContentType(&contentType)
content := "They were <b>awesome</b>!"
body.SetContent(&content)
requestBody.SetBody(body)
recipient := graphmodels.NewRecipient()
emailAddress := graphmodels.NewEmailAddress()
address := "AdeleV@contoso.onmicrosoft.com"
emailAddress.SetAddress(&address)
recipient.SetEmailAddress(emailAddress)
toRecipients := []graphmodels.Recipientable {
recipient,
requestBody.SetToRecipients(toRecipients)
result, err := graphClient.Me().Messages().Post(context.Background(), requestBody, nil)
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Message message = new Message();
message.subject = "Did you see last night's game?";
message.importance = Importance.LOW;
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "They were <b>awesome</b>!";
message.body = body;
LinkedList<Recipient> toRecipientsList = new LinkedList<Recipient>();
Recipient toRecipients = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "AdeleV@contoso.onmicrosoft.com";
toRecipients.emailAddress = emailAddress;
toRecipientsList.add(toRecipients);
message.toRecipients = toRecipientsList;
graphClient.me().messages()
.buildRequest()
.post(message);
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new Message();
$requestBody->setSubject('Did you see last night\'s game?');
$requestBody->setImportance(new Importance('low'));
$body = new ItemBody();
$body->setContentType(new BodyType('html'));
$body->setContent('They were <b>awesome</b>!');
$requestBody->setBody($body);
$toRecipientsRecipient1 = new Recipient();
$toRecipientsRecipient1EmailAddress = new EmailAddress();
$toRecipientsRecipient1EmailAddress->setAddress('AdeleV@contoso.onmicrosoft.com');
$toRecipientsRecipient1->setEmailAddress($toRecipientsRecipient1EmailAddress);
$toRecipientsArray []= $toRecipientsRecipient1;
$requestBody->setToRecipients($toRecipientsArray);
In the request body, supply a JSON representation of message object.
Response
Here is an example of the response. Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 Created
Content-type: application/json
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('94447c6e-ea4c-494c-a9ed-d905e366c5cb')/messages/$entity",
"@odata.etag":"W/\"CQAAABYAAABK4UfANE/UR5clSilZtIuWAAC1vdti\"",
"id":"AAMkADNlNYjSAAA=",
"createdDateTime":"2017-07-22T01:53:56Z",
"lastModifiedDateTime":"2017-07-22T01:53:57Z",
"changeKey":"CQAAABYAAABK4UfANE/UR5clSilZtIuWAAC1vdti",
"categories":[
"receivedDateTime":"2017-07-22T01:53:57Z",
"sentDateTime":"2017-07-22T01:53:57Z",
"hasAttachments":false,
"internetMessageId":"<MWHPR1301MB@MWHPR1301MB.namprd13.prod.outlook.com>",
"subject":"Did you see last night's game?",
"bodyPreview":"They were awesome!",
"importance":"low",
"parentFolderId":"AAMkADNlNWAAAAAAEPAAA=",
"conversationId":"AAQkADNlNFdXGBnqtY=",
"conversationIndex":"AQHTe7/VAniOJVgCxEmtF1z6ZY1rFQ==",
"isDeliveryReceiptRequested":false,
"isReadReceiptRequested":false,
"isRead":true,
"isDraft":true,
"webLink":"https://outlook.office365.com/owa/?ItemID=AAMkADNlNYjSAAA%3D&exvsurl=1&viewmodel=ReadMessageItem",
"inferenceClassification":"focused",
"body":{
"contentType":"html",
"content":"<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\nThey were <b>awesome</b>!\r\n</body>\r\n</html>\r\n"
"toRecipients":[
"emailAddress":{
"name":"Adele Vance",
"address":"AdeleV@contoso.onmicrosoft.com"
"ccRecipients":[
"bccRecipients":[
"replyTo":[
Request
JavaScript
PowerShell
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Message
Subject = "9/8/2018: concert",
Body = new ItemBody
ContentType = BodyType.Html,
Content = "The group represents Washington.",
ToRecipients = new List<Recipient>
new Recipient
EmailAddress = new EmailAddress
Address = "AlexW@contoso.OnMicrosoft.com",
InternetMessageHeaders = new List<InternetMessageHeader>
new InternetMessageHeader
Name = "x-custom-header-group-name",
Value = "Washington",
new InternetMessageHeader
Name = "x-custom-header-group-id",
Value = "WA001",
var result = await graphClient.Me.Messages.PostAsync(requestBody);
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewMessage()
subject := "9/8/2018: concert"
requestBody.SetSubject(&subject)
body := graphmodels.NewItemBody()
contentType := graphmodels.HTML_BODYTYPE
body.SetContentType(&contentType)
content := "The group represents Washington."
body.SetContent(&content)
requestBody.SetBody(body)
recipient := graphmodels.NewRecipient()
emailAddress := graphmodels.NewEmailAddress()
address := "AlexW@contoso.OnMicrosoft.com"
emailAddress.SetAddress(&address)
recipient.SetEmailAddress(emailAddress)
toRecipients := []graphmodels.Recipientable {
recipient,
requestBody.SetToRecipients(toRecipients)
internetMessageHeader := graphmodels.NewInternetMessageHeader()
name := "x-custom-header-group-name"
internetMessageHeader.SetName(&name)
value := "Washington"
internetMessageHeader.SetValue(&value)
internetMessageHeader1 := graphmodels.NewInternetMessageHeader()
name := "x-custom-header-group-id"
internetMessageHeader1.SetName(&name)
value := "WA001"
internetMessageHeader1.SetValue(&value)
internetMessageHeaders := []graphmodels.InternetMessageHeaderable {
internetMessageHeader,
internetMessageHeader1,
requestBody.SetInternetMessageHeaders(internetMessageHeaders)
result, err := graphClient.Me().Messages().Post(context.Background(), requestBody, nil)
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Message message = new Message();
message.subject = "9/8/2018: concert";
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "The group represents Washington.";
message.body = body;
LinkedList<Recipient> toRecipientsList = new LinkedList<Recipient>();
Recipient toRecipients = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "AlexW@contoso.OnMicrosoft.com";
toRecipients.emailAddress = emailAddress;
toRecipientsList.add(toRecipients);
message.toRecipients = toRecipientsList;
LinkedList<InternetMessageHeader> internetMessageHeadersList = new LinkedList<InternetMessageHeader>();
InternetMessageHeader internetMessageHeaders = new InternetMessageHeader();
internetMessageHeaders.name = "x-custom-header-group-name";
internetMessageHeaders.value = "Washington";
internetMessageHeadersList.add(internetMessageHeaders);
InternetMessageHeader internetMessageHeaders1 = new InternetMessageHeader();
internetMessageHeaders1.name = "x-custom-header-group-id";
internetMessageHeaders1.value = "WA001";
internetMessageHeadersList.add(internetMessageHeaders1);
message.internetMessageHeaders = internetMessageHeadersList;
graphClient.me().messages()
.buildRequest()
.post(message);
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new Message();
$requestBody->setSubject('9/8/2018: concert');
$body = new ItemBody();
$body->setContentType(new BodyType('html'));
$body->setContent('The group represents Washington.');
$requestBody->setBody($body);
$toRecipientsRecipient1 = new Recipient();
$toRecipientsRecipient1EmailAddress = new EmailAddress();
$toRecipientsRecipient1EmailAddress->setAddress('AlexW@contoso.OnMicrosoft.com');
$toRecipientsRecipient1->setEmailAddress($toRecipientsRecipient1EmailAddress);
$toRecipientsArray []= $toRecipientsRecipient1;
$requestBody->setToRecipients($toRecipientsArray);
$internetMessageHeadersInternetMessageHeader1 = new InternetMessageHeader();
$internetMessageHeadersInternetMessageHeader1->setName('x-custom-header-group-name');
$internetMessageHeadersInternetMessageHeader1->setValue('Washington');
$internetMessageHeadersArray []= $internetMessageHeadersInternetMessageHeader1;
$internetMessageHeadersInternetMessageHeader2 = new InternetMessageHeader();
$internetMessageHeadersInternetMessageHeader2->setName('x-custom-header-group-id');
$internetMessageHeadersInternetMessageHeader2->setValue('WA001');
$internetMessageHeadersArray []= $internetMessageHeadersInternetMessageHeader2;
$requestBody->setInternetMessageHeaders($internetMessageHeadersArray);
In the request body, supply a JSON representation of message object.
Response
Here is an example of the response. Note: Internet message headers are not returned by default in a POST response. The response object shown here may also be truncated for brevity. All of the properties will be returned from an actual call.
HTTP/1.1 201 Created
Content-type: application/json
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('7f180cbb-a5ae-457c-b7e8-6f5b42ba33e7')/messages/$entity",
"@odata.etag":"W/\"CQAAABYAAAC4ofQHEIqCSbQPot83AFcbAAAnjjuE\"",
"id":"AAMkADhNmAAA=",
"createdDateTime":"2018-09-09T02:54:56Z",
"lastModifiedDateTime":"2018-09-09T02:54:56Z",
"changeKey":"CQAAABYAAAC4ofQHEIqCSbQPot83AFcbAAAnjjuE",
"categories":[
"receivedDateTime":"2018-09-09T02:54:56Z",
"sentDateTime":"2018-09-09T02:54:56Z",
"hasAttachments":false,
"internetMessageId":"<MWHPR220MB1120.namprd22.prod.outlook.com>",
"subject":"9/8/2018: concert",
"bodyPreview":"The group represents Washington.",
"importance":"normal",
"parentFolderId":"AAMkADhAAAAAAEPAAA=",
"conversationId":"AAQkADhNCuP8OKSm-0NE=",
"isDeliveryReceiptRequested":false,
"isReadReceiptRequested":false,
"isRead":true,
"isDraft":true,
"webLink":"https://outlook.office365.com/owa/?ItemID=AAMkADhNmAAA%3D&exvsurl=1&viewmodel=ReadMessageItem",
"inferenceClassification":"focused",
"body":{
"contentType":"html",
"content":"<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\nThe group represents Washington.\r\n</body>\r\n</html>\r\n"
"toRecipients":[
"emailAddress":{
"name":"Alex Wilber",
"address":"AlexW@contoso.OnMicrosoft.com"
"ccRecipients":[
"bccRecipients":[
"replyTo":[
"flag":{
"flagStatus":"notFlagged"
Request
JavaScript
PowerShell
const client = Client.init(options);
const message = Q29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9wa2NzNy1taW1lOw0KCW5hbWU9c21pbWUucDdtOw0KCXNtaW1lLXR5cGU9ZW52ZWxvcGVkLWRhdGENCk1pbWUtVmVyc2lvbjogMS4wIChNYWMgT1MgWCBNYWlsIDEzLjAgXCgzNjAxLjAuMTBcKSkNClN1YmplY3Q6IFJlOiBUZXN0aW5nIFMvTUlNRQ0KQ29udGVudC1EaXNwb3Np...;
await client.api('/me/messages')
.post(message);
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('0aaa0aa0-0000-0a00-a00a-0000009000a0')/messages/$entity",
"@odata.etag": "W/\"AAAAAAAAAAAa00AAAa0aAaAa0a0AAAaAAAAaAa0a\"",
"id": "AAMkADA1MTAAAAqldOAAA=",
"createdDateTime": "2021-04-23T18:13:44Z",
"lastModifiedDateTime": "2021-04-23T18:13:44Z",
"changeKey": "AAAAAAAAAAAA00aaaa000aaA",
"categories": [],
"receivedDateTime": "2021-04-23T18:13:44Z",
"sentDateTime": "2021-02-28T07:15:00Z",
"hasAttachments": false,
"internetMessageId": "<AAAAAAAAAA@AAAAAAA0001AA0000.codcod00.prod.outlook.com>",
"subject": "Internal Resume Submission: Sales Associate",
"bodyPreview": "Hi, Megan.I have an interest in the Sales Associate position. Please consider my resume, which you can access here...",
"importance": "normal",
"parentFolderId": "LKJDSKJHkjhfakKJHFKWKKJHKJdhkjHDK==",
"conversationId": "SDSFSmFSDGI5LWZhYjc4fsdfsd=",
"conversationIndex": "Adfsdfsdfsdfw==",
"isDeliveryReceiptRequested": null,
"isReadReceiptRequested": false,
"isRead": true,
"isDraft": true,
"webLink": "https://outlook.office365.com/owa/?ItemID=AAMkAGNhOWAvsurl=1&viewmodel=ReadMessageItem",
"inferenceClassification": "focused",
"body": {
"contentType": "text",
"content": "Hi, Megan.I have an interest in the Sales Associate position. Please consider my resume, which you can access here... Regards,Alex"
"sender": {
"emailAddress": {
"name": "Alex Wilber",
"address": "AlexW@contoso.com"
"from": {
"emailAddress": {
"name": "Alex Wilber",
"address": "AlexW@contoso.com"
"toRecipients": [
"emailAddress": {
"name": "Megan Bowen",
"address": "MeganB@contoso.com"
"ccRecipients": [],
"bccRecipients": [],
"replyTo": [],
"flag": {
"flagStatus": "notFlagged"
If the request body includes malformed MIME content, this method returns the following error message.
HTTP/1.1 400 Bad Request
Content-type: application/json
"error": {
"code": "ErrorMimeContentInvalidBase64String",
"message": "Invalid base64 string for MIME content."
See also
Add custom data to resources using extensions
Add custom data to users using open extensions (preview)