Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Ben Girard -
Number of replies: 18
For the last 4 hours, I have read countless articles (all giving different advice) with no luck. I tried all possible combinations of ports, settings enabled authentication, firewall ports, MX records, etc...   I am at my wit's end.

Moodle should provide a clear step-by-step article on how to connect Moodle to our Office 365 to a noreply@domain.com since this is something that is frequently needed.

NOTE: I have multiple email domains, perhaps that is the issue...?

ERROR: Your site couldn't communicate with your mail server. Please check your outgoing mail configuration.

Average of ratings: -
In reply to Ben Girard

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Can Thunderbird send mails as noreply@domain.com through the SMTP provided by Office365? Once that is successful you have the parameters for Moodle SMTP configuration.
Average of ratings: Useful (1)
In reply to Visvanath Ratnaweera

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
This ^^^

Or, if you're really keen/desperate try this https://learn.microsoft.com/en-us/exchange/mail-flow/test-smtp-telnet?view=exchserver-2019

The point is that if you have the correct parameters, you're not firewalled and the mail server is configured properly then it will work as Moodle fully supports the SMTP protocol. One of those things is wrong and it's usually easier to troubleshoot it outside of Moodle. It's very common for hosting companies and ISPs to block SMTP to a greater or lesser extent to prevent SPAM.

Yes, it's frustrating. Been there many times. I sympathise.
In reply to Visvanath Ratnaweera

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Ben Girard -
My apologies, what is Thunderbird?
In reply to Ben Girard

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Open source (and free) mail client - Other mail clients are available.

https://www.thunderbird.net/
In reply to Howard Miller

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Ben Girard -
Thanks, I will try this email client and see if I can SMPT via Office 365.
In reply to Visvanath Ratnaweera

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Ben Girard -
Do you gentlemen have a cloud partner that you would recommend to get this resolved?
In reply to Ben Girard

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Nope.

However, we're not done yet. Where is your Moodle site hosted for a start?

I cannot overemphasise - do not try to resolve issues with connections to external sites/servers using Moodle itself. It's not what it's for - it doesn't have the diagnostic capabilities. Use a dedicated mail client or debug the protocol directly using (e.g.) telnet. It's not as bad as it sounds.
In reply to Howard Miller

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Ben Girard -
Hi Howard,
The Linux VM Moodle is hosted in Azure. I added the ports 587 to the firewall. I was planning to install Thunderbird and see if I can use Office 365 SMTP to confirm the settings and eliminate that portion of the pipeline/process.
In reply to Ben Girard

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
My Thunderbird suggestion was perhaps contra-productive.

This is the background story: As somebody who gives top priority to FOSS, Thunderbird is the mail client of my desktop and laptop. So I'm familiar in configuring it for the various mailboxes I use. My suggestion was for you to install Thunderbird on a desktop or a laptop, not on the server - the servers a) have no graphical user interface b) no monitor/screen to watch. Once you send mail from your Thunderbird through your SMTP provider you've found its configuration. Now enter them to Moodle.

Since you asked "What is Thunderbird", this path is too dark, I fear. Better avoid it.

Talking about "Cloud SMTP" providers, SMTP has nothing to do with "The Cloud" (whatever that is). Either take the DIY path with Exim, Postfix, etc. or go to a SMTP provider like Sendgrid, Mailgun, ...
In reply to Visvanath Ratnaweera

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Alejandro Lengua -
I am also a user a user of wordpress and noticed that there are some plugins that allow sending SMTP emails using Office 365 Oauth
so in theory it should be not impossible to do the same on Moodle.

You can see the following links if this issue is interesting to you
https://wordpress.org/plugins/wpo365-msgraphmailer/
https://wpsocket.com/plugin/post-smtp/
In reply to Ben Girard

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Ken Task -
Picture of Particularly helpful Moodlers
Install the following on your Moodle:
'SoS', Ken

Average of ratings: Useful (2)
In reply to Ken Task

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Ben Girard -
Great suggestion... I was only using the built-in "test email" but it doesn't provide much info...
In reply to Ben Girard

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
I fought with Gmail and the noreply email - it would work but always got sent to spam. I ended up installing postfix (a linux mailserver) on the server and then relaying to Gmail through that server and it worked like a charm...wonder if you couldn't do the same with Microsoft - I would be concerned that you would end up getting sent to spam too..
In reply to Emma Richardson

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Ken Task -
Picture of Particularly helpful Moodlers
Postfix can be installed and configured to be localhost - send only.
Can then setup a 'smart host' in Postfix to relay all but localhost mail to that 'smarthost'.   And, you do have mail logs locally to view use in trouble shooting - things you wouldn't see otherwise.
Moodle uses it's built in phpmailer which would talk to your localhost sendonly PostFix. No need to configure SMTP relay with moodle alone.

The 'smarthost' still has to be configured to accept mail from your moodle server.

'SoS', Ken

In reply to Ben Girard

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Ben Girard -
Decide to bypass using Exchange Online for SMTP, went with the Azure/SendGrid option, took 10 min, not a single issue.
In reply to Ben Girard

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Ken Task -
Picture of Particularly helpful Moodlers
Congrats!
Uhhh ... details on your 10 minute solution are lacking!
Care to add to Moodle docs?

Azure is virtualization - not mentioned in Moodle docs on the related topic (must admit I haven't searched).

I use SendGrid API Key myself so I know that is/or was in Moodle Docs! smile

'SoS', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Ben Girard -
I simply spun up a SendGrid SMTP service in Azure and pointed Moodle to it instead of fighting with the complexity of connecting Moodle to Office 365 Exchange, which proved to be nearly impossible.
Average of ratings: Useful (1)
In reply to Ben Girard

Re: Why is it nearly impossible to get Moodle to send email via Office 365 SMTP via a noreply account

by Mosaab Alsiddig -
I have faced this problem too and fixed by going to exchange -> mailboxes , then select the email I want to use with moodle, then "Setting" -> mail flow , then tick "turn off smtp" and "turn on TLS"

 
 
Average of ratings: Useful (1)