Send email thru Azure AD Graph API as email alias

杀马特。学长 韩版系。学妹 提交于 2021-01-28 21:24:52

问题


In the Graph API explorer, you can send an email with the endpoint
https://graph.microsoft.com/v1.0/me/sendMail
and a basic json payload of

"message": {
    "subject": "Meet for lunch?",
    "body": {
        "contentType": "Text",
        "content": "The new cafeteria is open."
    },
    "toRecipients": [
        {
            "emailAddress": {
                "address": "user@domain.com"
            }
        }
    ],
    "from":{
        "emailAddress": {
            "address": "smtp:my_alias@domain.com"
        }
    }
}


When I send this request, it still sends the email as user@domain.com instead of my email alias. I can still see the email alias there when i run the endpoint
https://graph.microsoft.com/beta/me/
Under proxyAddresses
I've looked over the documentation and don't see any clear example of option to send the email as alias.


回答1:


We can only set from and sender properties to a different value when sending a message from a shared mailbox, for a shared calendar, or as a delegate. See details here (see form and sender) and Setting the from and sender properties. Sending email as alias is not mentioned and cannot work based on the test.

So it's not supported to send the email as alias via Microsoft Graph API.

The value of from and sender must correspond to the actual mailbox used. So the only way to send email as alias is to change alias to primary email in O365 admin center and then send email.

As a workaround, if you just want recipients to think that you are sending from alias, you can configure a delegated mailbox for your mailbox (assign sendAs rights of the mailbox to a delegated user). Delegated mailbox is actually another mailbox and needs to be assigned an Exchange Online license. Then set the from property to the delegated user who have sendAs rights for your mailbox in Microsoft Graph API. See details here. After that, when you send an email, the recipient will see it's from the delegated email.

About how to assign sendAs rights in Exchange Admin Center, please refer to Use the EAC to assign permissions to individual mailboxes. It may take several hours to take effect.

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": "user@domain.com"
                }
            }
        ],
        "from": {
            "emailAddress": {
                "address": "{delegated mailbox}"
            }
        }
    }
}


来源:https://stackoverflow.com/questions/62437767/send-email-thru-azure-ad-graph-api-as-email-alias

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!