0 votes
by (260 points)

Hello,
I've an unattended app used to send email with EWS protocol.
I've registered the app as described on https://blog.rebex.net/office365-ews-oauth-unattended and added the permission "Send mail as any user".

The smtpAddess used on _ews.Settings.Impersonation is "service@domain.com"
The MailAddress on Sender and From of the Rebex.Mail.MailMessage is "user1@domain.com".

When I send the mail I get this error:
"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 (ErrorSendAsDenied)."

Can you help me to found what is wrong?

Thanks.

Applies to: Rebex Secure Mail

2 Answers

0 votes
by (148k points)

Hello, it looks like the permission you granted is not the one suitable for EWS. You have to add the "fullaccessas_app" permission, not "Mail.Send" (which is suitable for MS Graph API but not for EWS). Check out steps 11 and 12 in the [blog post](blog post) for details.

by (260 points)
Hello Lukas,
the application already has full_access_as_app and Mail.Send (it is part of Office 365 Exchange Online) permissions: you can check it on following picture  https://drive.google.com/file/d/1EueLe1Z7XpVqWvKikPFOzB_ThzlQnEhJ/view?usp=sharing

The problem is this:
- if "_ews.Settings.Impersonation" and "Sender/From" of the message are the same email it works
- if "_ews.Settings.Impersonation" and "Sender/From" of the message are different I get the error

"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 (ErrorSendAsDenied)."

Thanks
0 votes
by (73.6k points)

From the reported error it seems that you are missing permissions for the "service@domain.com" account.

Go to the Exchange admin center / Mailboxes page and click on the "service@domain.com" mailbox. Then click on the "Delegation" tab.

Then add the "Send as" permission for the "user1@domain.com" mailbox, by clicking the "Edit" button.

Similarly, if you want to add the "Send on behalf" permission click on the "Send on behalf" link.

enter image description here

...