You can't do that with the Graph (or any of the Mailbox API's) as they will always resolve back to the original sender or check that you have rights (SendAS or SendOnBehalf) to the send from the particular address your trying to use, probably the easiest way of working around it is create a Shared Mailbox that has that address and give the accounts you want to use SendAS to that mailbox (or if your using App permission you should be good to go). Then create an AutoReply rule on the Shared Mailbox to indicate that messages sent to that address aren't monitored.
How to set custom email sender name while using microsoft graph v1.0 API?
Hi I am using microsoft graph v1.0 APIs to send emails. I want to set a custom email sender name like "No Replyy", but this is not happening. Email is being received with user name instead. Graph APis are not honoring the name property inside the "from" key. Please let me know if there is a way to achieve this, or is there something i am doing wrong. Below is the request body json i am sending .
{
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "The new cafeteria is open."
},
"from": {
"emailAddress": {
"name" :"No Replyy",
"address": "noreply@.."
}
},
"toRecipients": [
{
"emailAddress": {
"address": "garthf@Company portal .com"
}
}
]
}
}
Microsoft Security | Microsoft Graph
3 answers
Sort by: Most helpful
-
-
RajeshKumarMSFT 1,976 Reputation points Microsoft External Staff
2022-02-11T09:32:47.143+00:00 Hello @Vibhore Gupta ,
Tried to replicate your use case please find the details below.
Send messages from another user account using Graph Explorer(delegated permission).
To perform this activity it requires Microsoft graph & mailbox permissions. With Mail.send.Shared graph permission with delegated.We have two types of mailbox permissions,
- Send on Behalf
- Send As for user account.
Please follow the this reference link for more details.
https://learn.microsoft.com/en-us/microsoft-365/admin/add-users/give-mailbox-permissions-to-another-user?view=o365-worldwide.User who logged in to your application with the Mail.Send.Shared permission MUST have one of these permissions
Send on Behalf or Send As
granted to the mailbox that the mail is from. Set from address to the mailbox address to which permissions are granted.If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment".
-
Ashish Omar 1 Reputation point
2022-05-23T07:01:37.333+00:00 while granting permission to the user, microsoft auth server would have asked user to validate user's identity and give consent to scope(send email)
when sending email, same user account is defaulted as fromAddress.
If you send HTTP request with different fromaddress than what was used to provide authorization, you will get this exception:{
"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."
}
}{
"message": {
"subject": "hi I am there?",
"body": {
"contentType": "Text",
"content": "example xyz-- hey ashish"}, "toRecipients": [ { "emailAddress": { "address": "******@gmail.com" } } ], "from": { "emailAddress": { "address": "******@gmail.com" } } }
}