Reputation: 11
I am currently using the Outlook REST API to send email. This is working fine when sending from a user mailbox such as:
https://outlook.office.com/api/v2.0/users/[email protected]/sendMail
'[email protected]' is the UPN of a valid user account in Azure AD.
What I need to do is 'send as' a shared mailbox. According to the documentation this can be achieved by changing the 'From' property in the JSON request body. An example would be:
{
"Message": {
"Subject": "Email Unit Test",
"Body": {
"ContentType": "HTML",
"Content": "Message body"
},
"ToRecipients": [
{
"EmailAddress": {
"Address": "[email protected]"
}
}
],
"Attachments": [
],
"From": {
"EmailAddress": {
"Address": "[email protected]"
}
},
"Sender": {
"EmailAddress": {
"Address": "[email protected]"
}
}
},
"SaveToSentItems": "false"
}
Now, when I give [email protected] 'Send As' and 'Send On Behalf Of' access to the shared mailbox this works. The recipient gets an email with the from field saying '[email protected] On Behalf Of [email protected]'. What I want however is for the email to appear as being sent from shared_mailbox only without the on behalf of user. To test this out further I removed the 'Send On Behalf Of' access and left 'Send As' access only. In the API I now get an error:
{
"error": {
"code": "ErrorSendAsDenied",
"message": "The user account which was used to submit this request does not have the right to send mail on behalf of the specified sending account., Cannot submit message."
}
}
Interestingly though, in my Outlook client I can still send an email from the shared mailbox and it works as expected with no 'on behalf of' in the From field. I'm starting to wonder whether this is a limitation of the REST API however there is nothing in the Microsoft docs to suggest this.
Has anyone had similar experiences with the REST API?
Upvotes: 1
Views: 1580
Reputation: 411
I tried to do the same thing and it seems the REST API allows you to implement "send on behalf of" but not "send as" feature.
Upvotes: 1