我们只能设置from
and sender
从共享邮箱、共享日历或作为代理人发送消息时,属性更改为不同的值。查看具体信息here https://learn.microsoft.com/en-us/graph/api/resources/message?view=graph-rest-1.0#properties (see form and sender) and 设置发件人和发件人属性 https://learn.microsoft.com/en-us/graph/outlook-create-send-messages#setting-the-from-and-sender-properties。没有提到以别名发送电子邮件,并且根据测试无法工作。
因此不支持通过 Microsoft Graph API 作为别名发送电子邮件。
的价值from
and sender
必须与实际使用的邮箱相对应。因此,以别名发送电子邮件的唯一方法是在 O365 管理中心将别名更改为主要电子邮件,然后发送电子邮件。
作为解决方法,如果您只是希望收件人认为您是从别名发送的,则可以为您的邮箱配置一个委派邮箱(分配sendAs邮箱对委派用户的权限)。委派邮箱实际上是另一个邮箱,需要分配 Exchange Online 许可证。然后设置from
财产授予被委托的用户sendAsMicrosoft Graph API 中您的邮箱的权限。查看具体信息here https://learn.microsoft.com/en-us/graph/outlook-create-send-messages#setting-the-from-and-sender-properties。之后,当您发送电子邮件时,收件人将看到该电子邮件来自委托电子邮件。
关于如何分配sendAsExchange 管理中心的权限,请参阅使用 EAC 为各个邮箱分配权限 https://learn.microsoft.com/en-us/exchange/recipients-in-exchange-online/manage-permissions-for-recipients#use-the-eac-to-assign-permissions-to-individual-mailboxes。可能需要几个小时才能生效。
POST https://graph.microsoft.com/beta/me/sendMail
{
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "The new cafeteria is open."
},
"toRecipients": [{
"emailAddress": {
"address": "[email protected] /cdn-cgi/l/email-protection"
}
}
],
"from": {
"emailAddress": {
"address": "{delegated mailbox}"
}
}
}
}