命名空间:microsoft.graph
采用 JSON 或 MIME 格式创建新邮件的草稿。
使用 JSON 格式时,可以:
- 包含附件到邮件中。
- 随后更新草稿以将内容添加到正文,或更改其他邮件属性。
使用 MIME 格式时:
默认情况下,此操作将草稿保存在“草稿”文件夹中。
在后续操作中发送草稿消息。
或者,通过一次操作发送新邮件 ,或创建一个草稿以转发、答复和答复所有现有邮件。
*
注意: S/MIME 消息有效负载当前限制为 4 MB。 超过此限制的提交尝试将导致 HTTP 413 Request Entity Too Large
错误响应。
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
✅ |
权限
调用此 API 需要下列权限之一。 若要了解详细信息,包括如何选择权限的信息,请参阅权限。
权限类型 |
权限(从最低特权到最高特权) |
委派(工作或学校帐户) |
Mail.ReadWrite |
委派(个人 Microsoft 帐户) |
Mail.ReadWrite |
应用程序 |
Mail.ReadWrite |
HTTP 请求
POST /me/messages
POST /users/{id|userPrincipalName}/messages
POST /me/mailFolders/{id}/messages
POST /users/{id | userPrincipalName}/mailFolders/{id}/messages
名称 |
类型 |
说明 |
Authorization |
string |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
Content-Length |
number |
0。必需。 |
Content-Type |
string |
实体正文中的数据性质。 必填。 对 JSON 对象使用 application/json ,对 MIME 内容使用 text/plain 。 |
请求正文
使用 JSON 格式时,请提供消息对象的 JSON 表示形式。
当指定 MIME 格式的正文时,请提供 MIME 内容与适用的 Internet 邮件头(“收件人”、“抄送”、“密件抄送”、“主题”)所有内容在请求正文中编码为 base64 格式。
由于邮件资源支持扩展因此可以使用 POST
操作,并在创建邮件时向其添加含有自己的数据的自定义属性。
响应
如果成功,此方法在响应正文中返回 201 Created
响应代码和 message 对象。
如果请求正文包含错误的 MIME 内容,此方法将返回 400 Bad request
和以下错误消息:“无效的 base64 字符串 MIME 内容”。
示例
请求
以下示例显示了一个请求。
POST https://graph.microsoft.com/v1.0/me/messages
Content-type: application/json
{
"subject":"Did you see last night's game?",
"importance":"Low",
"body":{
"contentType":"HTML",
"content":"They were <b>awesome</b>!"
},
"toRecipients":[
{
"emailAddress":{
"address":"AdeleV@contoso.com"
}
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
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.com",
},
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.Messages.PostAsync(requestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
mgc users messages create --user-id {user-id} --body '{\
"subject":"Did you see last night's game?",\
"importance":"Low",\
"body":{\
"contentType":"HTML",\
"content":"They were <b>awesome</b>!"\
},\
"toRecipients":[\
{\
"emailAddress":{\
"address":"AdeleV@contoso.com"\
}\
}\
]\
}\
'
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
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.com"
emailAddress.SetAddress(&address)
recipient.SetEmailAddress(emailAddress)
toRecipients := []graphmodels.Recipientable {
recipient,
}
requestBody.SetToRecipients(toRecipients)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
messages, err := graphClient.Me().Messages().Post(context.Background(), requestBody, nil)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Message message = new Message();
message.setSubject("Did you see last night's game?");
message.setImportance(Importance.Low);
ItemBody body = new ItemBody();
body.setContentType(BodyType.Html);
body.setContent("They were <b>awesome</b>!");
message.setBody(body);
LinkedList<Recipient> toRecipients = new LinkedList<Recipient>();
Recipient recipient = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.setAddress("AdeleV@contoso.com");
recipient.setEmailAddress(emailAddress);
toRecipients.add(recipient);
message.setToRecipients(toRecipients);
Message result = graphClient.me().messages().post(message);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const message = {
subject: 'Did you see last night\'s game?',
importance: 'Low',
body: {
contentType: 'HTML',
content: 'They were <b>awesome</b>!'
},
toRecipients: [
{
emailAddress: {
address: 'AdeleV@contoso.com'
}
}
]
};
await client.api('/me/messages')
.post(message);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\Message;
use Microsoft\Graph\Generated\Models\Importance;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\BodyType;
use Microsoft\Graph\Generated\Models\Recipient;
use Microsoft\Graph\Generated\Models\EmailAddress;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$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.com');
$toRecipientsRecipient1->setEmailAddress($toRecipientsRecipient1EmailAddress);
$toRecipientsArray []= $toRecipientsRecipient1;
$requestBody->setToRecipients($toRecipientsArray);
$result = $graphServiceClient->me()->messages()->post($requestBody)->wait();
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.Mail
$params = @{
subject = "Did you see last night's game?"
importance = "Low"
body = @{
contentType = "HTML"
content = "They were <b>awesome</b>!"
}
toRecipients = @(
@{
emailAddress = @{
address = "AdeleV@contoso.com"
}
}
)
}
# A UPN can also be used as -UserId.
New-MgUserMessage -UserId $userId -BodyParameter $params
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.message import Message
from msgraph.generated.models.importance import Importance
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.body_type import BodyType
from msgraph.generated.models.recipient import Recipient
from msgraph.generated.models.email_address import EmailAddress
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Message(
subject = "Did you see last night's game?",
importance = Importance.Low,
body = ItemBody(
content_type = BodyType.Html,
content = "They were <b>awesome</b>!",
),
to_recipients = [
Recipient(
email_address = EmailAddress(
address = "AdeleV@contoso.com",
),
),
],
)
result = await graph_client.me.messages.post(request_body)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
在请求正文中,提供 Message 对象的 JSON 表示形式。
响应
以下示例显示了相应的响应。 注意:为了提高可读性,可能缩短了此处显示的响应对象。
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.com"
}
}
],
"ccRecipients":[
],
"bccRecipients":[
],
"replyTo":[
]
}
请求
POST https://graph.microsoft.com/v1.0/me/messages
Content-type: application/json
{
"subject":"9/8/2018: concert",
"body":{
"contentType":"HTML",
"content":"The group represents Washington."
},
"toRecipients":[
{
"emailAddress":{
"address":"AlexW@contoso.com"
}
}
],
"internetMessageHeaders":[
{
"name":"x-custom-header-group-name",
"value":"Washington"
},
{
"name":"x-custom-header-group-id",
"value":"WA001"
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
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.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",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.Messages.PostAsync(requestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
mgc users messages create --user-id {user-id} --body '{\
"subject":"9/8/2018: concert",\
"body":{\
"contentType":"HTML",\
"content":"The group represents Washington."\
},\
"toRecipients":[\
{\
"emailAddress":{\
"address":"AlexW@contoso.com"\
}\
}\
],\
"internetMessageHeaders":[\
{\
"name":"x-custom-header-group-name",\
"value":"Washington"\
},\
{\
"name":"x-custom-header-group-id",\
"value":"WA001"\
}\
]\
}\
'
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
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.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)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
messages, err := graphClient.Me().Messages().Post(context.Background(), requestBody, nil)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Message message = new Message();
message.setSubject("9/8/2018: concert");
ItemBody body = new ItemBody();
body.setContentType(BodyType.Html);
body.setContent("The group represents Washington.");
message.setBody(body);
LinkedList<Recipient> toRecipients = new LinkedList<Recipient>();
Recipient recipient = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.setAddress("AlexW@contoso.com");
recipient.setEmailAddress(emailAddress);
toRecipients.add(recipient);
message.setToRecipients(toRecipients);
LinkedList<InternetMessageHeader> internetMessageHeaders = new LinkedList<InternetMessageHeader>();
InternetMessageHeader internetMessageHeader = new InternetMessageHeader();
internetMessageHeader.setName("x-custom-header-group-name");
internetMessageHeader.setValue("Washington");
internetMessageHeaders.add(internetMessageHeader);
InternetMessageHeader internetMessageHeader1 = new InternetMessageHeader();
internetMessageHeader1.setName("x-custom-header-group-id");
internetMessageHeader1.setValue("WA001");
internetMessageHeaders.add(internetMessageHeader1);
message.setInternetMessageHeaders(internetMessageHeaders);
Message result = graphClient.me().messages().post(message);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const message = {
subject: '9/8/2018: concert',
body: {
contentType: 'HTML',
content: 'The group represents Washington.'
},
toRecipients: [
{
emailAddress: {
address: 'AlexW@contoso.com'
}
}
],
internetMessageHeaders: [
{
name: 'x-custom-header-group-name',
value: 'Washington'
},
{
name: 'x-custom-header-group-id',
value: 'WA001'
}
]
};
await client.api('/me/messages')
.post(message);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\Message;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\BodyType;
use Microsoft\Graph\Generated\Models\Recipient;
use Microsoft\Graph\Generated\Models\EmailAddress;
use Microsoft\Graph\Generated\Models\InternetMessageHeader;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$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.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);
$result = $graphServiceClient->me()->messages()->post($requestBody)->wait();
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.Mail
$params = @{
subject = "9/8/2018: concert"
body = @{
contentType = "HTML"
content = "The group represents Washington."
}
toRecipients = @(
@{
emailAddress = @{
address = "AlexW@contoso.com"
}
}
)
internetMessageHeaders = @(
@{
name = "x-custom-header-group-name"
value = "Washington"
}
@{
name = "x-custom-header-group-id"
value = "WA001"
}
)
}
# A UPN can also be used as -UserId.
New-MgUserMessage -UserId $userId -BodyParameter $params
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.message import Message
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.body_type import BodyType
from msgraph.generated.models.recipient import Recipient
from msgraph.generated.models.email_address import EmailAddress
from msgraph.generated.models.internet_message_header import InternetMessageHeader
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Message(
subject = "9/8/2018: concert",
body = ItemBody(
content_type = BodyType.Html,
content = "The group represents Washington.",
),
to_recipients = [
Recipient(
email_address = EmailAddress(
address = "AlexW@contoso.com",
),
),
],
internet_message_headers = [
InternetMessageHeader(
name = "x-custom-header-group-name",
value = "Washington",
),
InternetMessageHeader(
name = "x-custom-header-group-id",
value = "WA001",
),
],
)
result = await graph_client.me.messages.post(request_body)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
在请求正文中,提供 Message 对象的 JSON 表示形式。
响应
以下示例显示了相应的响应。 注意:默认情况下,POST 响应中不会返回 Internet 邮件标头。 为简洁起见,也可能会截断此处显示的响应对象。 所有属性都将通过实际调用返回。
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.com"
}
}
],
"ccRecipients":[
],
"bccRecipients":[
],
"replyTo":[
],
"flag":{
"flagStatus":"notFlagged"
}
}
请求
POST https://graph.microsoft.com/v1.0/me/messages
Content-type: text/plain
Q29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9wa2NzNy1taW1lOw0KCW5hbWU9c21pbWUucDdtOw0KCXNtaW1lLXR5cGU9ZW52ZWxvcGVkLWRhdGENCk1pbWUtVmVyc2lvbjogMS4wIChNYWMgT1MgWCBNYWlsIDEzLjAgXCgzNjAxLjAuMTBcKSkNClN1YmplY3Q6IFJlOiBUZXN0aW5nIFMvTUlNRQ0KQ29udGVudC1EaXNwb3Np...
mgc users messages create --user-id {user-id} --body 'Q29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9wa2NzNy1taW1lOw0KCW5hbWU9c21pbWUucDdtOw0KCXNtaW1lLXR5cGU9ZW52ZWxvcGVkLWRhdGENCk1pbWUtVmVyc2lvbjogMS4wIChNYWMgT1MgWCBNYWlsIDEzLjAgXCgzNjAxLjAuMTBcKSkNClN1YmplY3Q6IFJlOiBUZXN0aW5nIFMvTUlNRQ0KQ29udGVudC1EaXNwb3Np...\
\
'
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const message = Q29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9wa2NzNy1taW1lOw0KCW5hbWU9c21pbWUucDdtOw0KCXNtaW1lLXR5cGU9ZW52ZWxvcGVkLWRhdGENCk1pbWUtVmVyc2lvbjogMS4wIChNYWMgT1MgWCBNYWlsIDEzLjAgXCgzNjAxLjAuMTBcKSkNClN1YmplY3Q6IFJlOiBUZXN0aW5nIFMvTUlNRQ0KQ29udGVudC1EaXNwb3Np...;
await client.api('/me/messages')
.post(message);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.Mail
$params = Q29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9wa2NzNy1taW1lOw0KCW5hbWU9c21pbWUucDdtOw0KCXNtaW1lLXR5cGU9ZW52ZWxvcGVkLWRhdGENCk1pbWUtVmVyc2lvbjogMS4wIChNYWMgT1MgWCBNYWlsIDEzLjAgXCgzNjAxLjAuMTBcKSkNClN1YmplY3Q6IFJlOiBUZXN0aW5nIFMvTUlNRQ0KQ29udGVudC1EaXNwb3Np...
# A UPN can also be used as -UserId.
New-MgUserMessage -UserId $userId -BodyParameter $params
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
响应
以下示例显示了相应的响应。
HTTP/1.1 201 Created
Content-type: application/json
{
"@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"
}
}
如果请求正文包含错误的 MIME 内容,此方法返回以下错误消息。
HTTP/1.1 400 Bad Request
Content-type: application/json
{
"error": {
"code": "ErrorMimeContentInvalidBase64String",
"message": "Invalid base64 string for MIME content."
}
}
相关内容