We use in our company email addresses for each employee and for 3 departments (service, support and reports) - for example <employee_name>@<company_name>.de
or support@<company_name>.de
("<..._name>" is just a placholder for posting here). Our programs use PHPMailer for sending Emails from the 3 departments via SMTP without user interaction (Host: smtp.office365.com
), that means the PHPMailer is called by programs/scripts that are started by the Microsoft Task Scheduler on a computer where none of our Microsoft-Users is logged in. Now we want to switch from Basic SMTP Auth to Oauth2.
So we registered in the main tenant (<boss_name>@<company_name>.de
) in the azure portal a web app "PHPMailer" and received the refresh token with the file "get_oauth_token.php", which is included in PHPMailer. The mail order via OAuth is working now, but only when <boss_name>@<company_name>.de
is the username
and the email sender (From
).
It's not working when both are for example reports@<company_name>.de
(prefered way)
SMTP INBOUND: "535 5.7.3 Authentication unsuccessful [AM6PR10CA0036.EURPRD10.PROD.OUTLOOK.COM]"
And it's not working when <boss_name>@<company_name>.de
is the username
and From
is for example reports@<company_name>.de
(willy-nilly compromise)
SMTP INBOUND: "554 5.2.252 SendAsDenied; <boss_name>@<company_name>.de not allowed to send as reports@<company_name>.de
We tried to change the configuration for <boss_name>@<company_name>.de
("SendAs" parameter) and of the app in the azure portal (for example defining the department email addresses as owner of the app or adding Mail.Send
in the Micrsoft Graph API as application permission) and waited 24 hours (synchronization delay) - but no change.
So i've read in the past weeks countless tutorials from Microsoft, PHPMailer and others, and forums like stackoverflow. But nowhere i could find the necessary information, how to change the configuration.
Examples:
Microsoft
Give mailbox permissions to another Microsoft 365 user - Admin help
Authenticate an IMAP, POP or SMTP connection using OAuth
Get access on behalf of a user
PHPMailer
Using Gmail with XOAUTH2 (unfortunately no explanation for Microsoft)
Basic Usage of the OAuth 2.0 Client from the PHP League
Microsoft Provider for OAuth 2.0 Client Microsoft OAuth 2.0 support for PHPMailer from Steven Maguire
But in this answer to my older question @ADyson wrote that the app just needs the appropriate permissions in the Graph API - so it must be possible. Unfortunately he didn't write, how to set the permissions...
So, how can i achieve my goal?
(Because the PHPMailer is working and i think it's just a configuration problem, i omitted code snippets. If you although need code or more information, please tell me...)
Update:
PHPMailer
Thanks to @greew i found a well made explanation with helpfull screenshots for delegated permissions:
Microsoft Azure and XOAUTH2 setup guide
Unfortunately it doesn't help for my case with application permissions, because it is made for the case, that the Microsoft user is logged in on the compauter where PHPMailer is working.
Not supported?
I found in the Microsoft page Authenticate an IMAP, POP or SMTP connection using OAuth the following hint:
Note As per the current test with SMTP Oauth 2.0 client credential flow with non-interactive sign in is not supported.
Does this mean, that i'm trying it for nothing, because it is not supported???
which
permissions are needed for sending emails in the name of an email address, that is listed in our tenant, via SMTP (we don't use IMAP or POP3). For example isUser.Read.All
important or not - because in many examples this permission is included, but in other places is written, that you only needMail.Send
... – Cadmarsingle tenant
for supported type, others suggest to definemultitenant
. I tried both - unsuccessfully. (We have only one tenant with many listed email addresses) – CadmarNote As per the current test with SMTP Oauth 2.0 client credential flow with non-interactive sign in is not supported.
- Does this mean, that it's actually not possible? – Cadmar