消息:答复
本文内容
命名空间:microsoft.graph
使用 JSON 或 MIME 格式 答复邮件的发件人。
使用 JSON 格式时:
指定参数的 comment 或 message body 属性。 指定这两者将返回 HTTP 400 错误请求错误。
如果原始邮件在 replyTo 属性中指定收件人,则根据 Internet 邮件格式 (RFC 2822 ) ,将答复发送给 replyTo 中的收件人,而不是 from 属性中的收件人。
使用 MIME 格式时:
此方法将邮件保存在 “已发送邮件” 文件夹中。
或者,创建一个草稿以答复现有邮件 ,并稍后 发送。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Mail.Send
委派(个人 Microsoft 帐户)
Mail.Send
应用程序
Mail.Send
HTTP 请求
POST /me/messages/{id}/reply
POST /users/{id | userPrincipalName}/messages/{id}/reply
POST /me/mailFolders/{id}/messages/{id}/reply
POST /users/{id | userPrincipalName}/mailFolders/{id}/messages/{id}/reply
名称
类型
说明
Authorization
string
Bearer {token}。 必填
Content-Type
string
实体正文中的数据性质。 必填 对 JSON 对象使用 application/json,对 MIME 内容使用 text/plain。
请求正文
使用 JSON 格式时,在请求正文中提供具有以下参数的 JSON 对象。
参数
类型
说明
注释
String
要包含的注释。可以为空字符串。
消息
message
回复邮件中要更新的任何可写属性。
当指定 MIME 格式的正文时,向 MIME 内容提供适用的 Internet 邮件头,所有邮件头在请求正文中都以 base64 格式进行编码。 此方法使用原始邮件的发件人作为收件人。
响应
如果成功,此方法返回 202 Accepted 响应代码。它不在响应正文中返回任何内容。
如果请求正文包含错误的 MIME 内容,此方法将返回 400 Bad request 和以下错误消息:“无效的 base64 字符串 MIME 内容”。
示例
以下示例包含注释,并将收件人添加到回复邮件中。
请求
下面是一个请求示例。
POST https://graph.microsoft.com/v1.0/me/messages/AAMkADA1MTAAAAqldOAAA=/reply
Content-Type: application/json
{
"message":{
"toRecipients":[
{
"emailAddress": {
"address":"samanthab@contoso.onmicrosoft.com",
"name":"Samantha Booth"
}
},
{
"emailAddress":{
"address":"randiw@contoso.onmicrosoft.com",
"name":"Randi Welch"
}
}
]
},
"comment": "Samantha, Randi, would you name the group please?"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var message = new Message
{
ToRecipients = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "samanthab@contoso.onmicrosoft.com",
Name = "Samantha Booth"
}
},
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "randiw@contoso.onmicrosoft.com",
Name = "Randi Welch"
}
}
}
};
var comment = "Samantha, Randi, would you name the group please?";
await graphClient.Me.Messages["{message-id}"]
.Reply(message,comment)
.Request()
.PostAsync();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const reply = {
message: {
toRecipients: [
{
emailAddress: {
address: 'samanthab@contoso.onmicrosoft.com',
name: 'Samantha Booth'
}
},
{
emailAddress: {
address: 'randiw@contoso.onmicrosoft.com',
name: 'Randi Welch'
}
}
]
},
comment: 'Samantha, Randi, would you name the group please?'
};
await client.api('/me/messages/AAMkADA1MTAAAAqldOAAA=/reply')
.post(reply);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/messages/AAMkADA1MTAAAAqldOAAA=/reply"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
MSGraphMessage *message = [[MSGraphMessage alloc] init];
NSMutableArray *toRecipientsList = [[NSMutableArray alloc] init];
MSGraphRecipient *toRecipients = [[MSGraphRecipient alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setAddress:@"samanthab@contoso.onmicrosoft.com"];
[emailAddress setName:@"Samantha Booth"];
[toRecipients setEmailAddress:emailAddress];
[toRecipientsList addObject: toRecipients];
MSGraphRecipient *toRecipients = [[MSGraphRecipient alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setAddress:@"randiw@contoso.onmicrosoft.com"];
[emailAddress setName:@"Randi Welch"];
[toRecipients setEmailAddress:emailAddress];
[toRecipientsList addObject: toRecipients];
[message setToRecipients:toRecipientsList];
payloadDictionary[@"message"] = message;
NSString *comment = @"Samantha, Randi, would you name the group please?";
payloadDictionary[@"comment"] = comment;
NSData *data = [NSJSONSerialization dataWithJSONObject:payloadDictionary options:kNilOptions error:&error];
[urlRequest setHTTPBody:data];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Message message = new Message();
LinkedList<Recipient> toRecipientsList = new LinkedList<Recipient>();
Recipient toRecipients = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "samanthab@contoso.onmicrosoft.com";
emailAddress.name = "Samantha Booth";
toRecipients.emailAddress = emailAddress;
toRecipientsList.add(toRecipients);
Recipient toRecipients1 = new Recipient();
EmailAddress emailAddress1 = new EmailAddress();
emailAddress1.address = "randiw@contoso.onmicrosoft.com";
emailAddress1.name = "Randi Welch";
toRecipients1.emailAddress = emailAddress1;
toRecipientsList.add(toRecipients1);
message.toRecipients = toRecipientsList;
String comment = "Samantha, Randi, would you name the group please?";
graphClient.me().messages("AAMkADA1MTAAAAqldOAAA=")
.reply(MessageReplyParameterSet
.newBuilder()
.withMessage(message)
.withComment(comment)
.build())
.buildRequest()
.post();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.New()
message := msgraphsdk.NewMessage()
requestBody.SetMessage(message)
message.SetToRecipients( []Recipient {
msgraphsdk.NewRecipient(),
emailAddress := msgraphsdk.NewEmailAddress()
SetEmailAddress(emailAddress)
address := "samanthab@contoso.onmicrosoft.com"
emailAddress.SetAddress(&address)
name := "Samantha Booth"
emailAddress.SetName(&name)
msgraphsdk.NewRecipient(),
emailAddress := msgraphsdk.NewEmailAddress()
SetEmailAddress(emailAddress)
address := "randiw@contoso.onmicrosoft.com"
emailAddress.SetAddress(&address)
name := "Randi Welch"
emailAddress.SetName(&name)
}
comment := "Samantha, Randi, would you name the group please?"
requestBody.SetComment(&comment)
messageId := "message-id"
graphClient.Me().MessagesById(&messageId).Reply(message-id).Post(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.Users.Actions
$params = @{
Message = @{
ToRecipients = @(
@{
EmailAddress = @{
Address = "samanthab@contoso.onmicrosoft.com"
Name = "Samantha Booth"
}
}
@{
EmailAddress = @{
Address = "randiw@contoso.onmicrosoft.com"
Name = "Randi Welch"
}
}
)
}
Comment = "Samantha, Randi, would you name the group please?"
}
# A UPN can also be used as -UserId.
Invoke-MgReplyUserMessage -UserId $userId -MessageId $messageId -BodyParameter $params
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
下面是一个响应示例。
HTTP/1.1 202 Accepted
请求
POST https://graph.microsoft.com/v1.0/me/messages/AAMkADA1MTAAAAqldOAAA=/reply
Content-type: text/plain
Q29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9wa2NzNy1taW1lOw0KCW5hbWU9c21pbWUucDdtOw0KCXNtaW1lLXR5cGU9ZW52ZWxvcGVkLWRhdGENCk1pbWUtVmVyc2lvbjogMS4wIChNYWMgT1MgWCBNYWlsIDEzLjAgXCgzNjAxLjAuMTBcKSkNClN1YmplY3Q6IFJlOiBUZXN0aW5nIFMvTUlNRQ0KQ29udGVudC1EaXNwb3Np
响应
下面是一个响应示例。
HTTP/1.1 202 Accepted
如果请求正文包含错误的 MIME 内容,此方法返回以下错误消息。
HTTP/1.1 400 Bad Request
Content-type: application/json
{
"error": {
"code": "ErrorMimeContentInvalidBase64String",
"message": "Invalid base64 string for MIME content."
}
}