There can be many scenarios for wanting to send emails from your Joomla website. For example, this blog website needs to send emails to new members so they can authenticate their membership request, and it also sends an email to me if somewone writes a comment on an article. Another Joomla website that I run needs to send an email to me if someone fills out the contact form and clicks the Send button.
My company uses Microsoft Office 365, so the obvious solution for me is to send emails via one of those email accounts. But getting it to work was a bit problematic, partially due to the problems created by spammers. Microsoft obviously does not want to be involved in sending spam emails, so it requires something called an SPF record to be created for the domain name used in the Office 365 email address.
Go to System - Global Configuration - Server
Enter the above specifications. The "from email" and the "SMTP username" can be the same. Remember to click Save.
You can try to click Send Test Mail at this point, but it may not work until you've created the SPF record for the email adddress domain name.
Creating an SPF record for the domain name
This assumes that you own the domain name used in the Office 365 email address, for example mysupercompany.com, and have access to the administration pages for the domain name at the domain name registration company.
The exact dialogs for doing this will be different for each domain name registration company. Here's what it looks like for a certain Danish domain registration company. First you say you want to add a TXT record to the domain name records, and then you enter information like this:
The important part is the text, which should specify the fixed IP address of the Joomla website, exactly as follows:
v=spf1 ip4:18.104.22.168 include:outlook.com ~all
Remember also that you're doing this for the domain name used in the Office 365 email address, not the domain name of the Joomla website. But the IP address is for the Joomla website. In effect, you're telling Microsoft that it can trust emails coming from that location as being non-spam emails.
Once this is in place things should begin to work, although maybe not immediately - it may take a bit of time for DNS record dissemination to get the updated info to Microsoft.