Specifying the Exchange Online SMTP server when sending SMTP mail is what MS calls "Direct Send":
https://learn.microsoft.com/en-us/exchange/mail-flow-best-practices/how-to-set-up-a-multifunction-device-or-application-to-send-email-using-microsoft-365-or-office-365#option-2-send-mail-directly-from-your-printer-or-application-to-microsoft-365-or-office-365-direct-sendIn practice, I've found this works only if the IP address of the sender is in the recipient's DNS SPF record (the article claims this is optional). The SPF record defines addresses which are allowed to send mail on behalf of the domain.
For example, suppose:
- The public IPv4 address of the site you're sending from is 123.123.123.123
- You're trying to use SMTP to send an e-mail to
someone@xyz.com, where xyz.com's mail is hosted on Exchange Online
This will work only if the IPv4 address 123.123.123.123 is included in the DNS SPF record for the domain xyz.com. ISTR the "From" address must also be in the recipient's domain, even if it isn't a real address or mailbox e.g. the "From" address must be something like MyApplication@xyz.com.
If you can meet these conditions, it "just works". No authentication is needed.
Note that if a sysadmin updates a DNS SPF record, the changes may take an hour or longer to propagate across the internet and come into effect.
You may find that your client's site already meets the SPF record requirement, but your home or office public IP address does not. This would cause your tests from your own site to fail, but work fine at the client site.
As you've already found, you can work around these requirements by specifying an SMTP server other than Exchange Online. Back when POP3/SMTP mail was king, everyone's ISP provided an SMTP server for use with their customers' outgoing mail. Many ISPs no longer offer an SMTP server, so customers have to look elsewhere.
Regards. Al
"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov
Neither a despot, nor a doormat, be
Every app wants to be a database app when it grows up