Office 365 SMTP and Moodle

Office 365 SMTP and Moodle

Rich Solomon -
回帖数:21
Hi all, I've searched and tried almost all of the tips I could find here in the forums and online, and I'm still stuck.  I'm hoping for some help.  Here are my settings...





I've also seen notes that suggest that the Moodle support email match, so I did that already as well.

This email account does have SMTP as an email app allowed on the 365 side of things, and is working fine for a WordPress site.  But I still keep getting this on my Moodle site, regardless of a From Username, or Subject here in the test area:


This is frustrating!  Any thoughts are welcome!

平均分:Useful (1)
回复Rich Solomon

Re: Office 365 SMTP and Moodle

Ken Task -
Particularly helpful Moodlers的头像
Under 'any thoughts' ...

First, I don't use office365 ...

The error suggest networking issue.
Got command line?   Investigate:

nmap -P0 -p 587 smtp.office365.com

You can add multiple ports by adding ,port#, port#


I just did a test:

nmap -P0 -p 587 smtp.office365.com
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2023-09-15 17:36 CDT
Nmap scan report for smtp.office365.com (40.99.245.34)
Host is up (0.026s latency).
Other addresses for smtp.office365.com (not scanned): 2603:1036:305:3889::2 2603:1036:305:4018::2 2603:1036:305:38b4::2 2603:1036:305:300b::2 2603:1036:305:48cb::2 2603:1036:305:3000::2 2603:1036:305:4948::2 2603:1036:305:3427::2 40.99.168.242 52.96.122.98 52.96.121.178 52.96.121.226 52.96.90.18 52.96.10.242 52.96.57.2

PORT    STATE SERVICE
587/tcp open  submission

Says I should be able to communicate with it ... state open.
But notice Other addresses ... 8 of those are IPv6, 7 are IPv4
Of the 7, 6 are of the same Class B block of IP's 52.96.x.x.

Wouldn't be surprised if your nmap scan the same FQDN renders different IP's.

When using a FQDN a DNS look has to be performed.
What are your servers DNS resolvers?

The other test ... a traceroute to the FQDN you are using.

'SoS', Ken

回复Ken Task

Re: Office 365 SMTP and Moodle

Rich Solomon -
I dont have command line unfortunately.  

Our webserver is a fully hosted provided at GoDaddy.  Fairly turnkey now with our website and our Moodle install.

Our website is a Wordpress install (co-located with the Moodle install), and the SMTP calls from the WP site are fine.  I was following the Moodle guides on for usong O365 as the relay, so thats where Ive been getting the settings thus far.

回复Rich Solomon

Re: Office 365 SMTP and Moodle

Ken Task -
Particularly helpful Moodlers的头像
Contract GoDaddy Support!

'SoS', Ken

回复Ken Task

Re: Office 365 SMTP and Moodle

Rich Solomon -
Well unfortunately, since the SMTP relay is working fine from one application on the same web server, they wont support it failing from within a different application.  Its not a web server issue.  The SMTP settings work on O365 as that other application accesses it fine.  This is truly within Moodle unfortunately.
回复Rich Solomon

Re: Office 365 SMTP and Moodle

Ken Task -
Particularly helpful Moodlers的头像
Who is 'they'?

Have you looked at any error logs on your server?

Fact that it reports immediately, 'can't communicate' points to outgoing ports allowed and network - me thinks.   But that's an educated guess as I don't host where you host and don't have access to your setup ... not that i am asking for that access either!

Does the SMTP relay service have caps?  X # messages allowed in a 24 hour period.   Have you access to the SMTP  service logs?

Let's compare:
https://wordpress.com/go/website-building/wordpress-smtp-settings-a-how-to-guide-for-email/

Moodle
https://docs.moodle.org/402/en/Mail_configuration

Under the hood, Moodle uses phpmailer.   What does WP use?

In higher version of moodle (you've not mentioned what version of Moodle you have),
I see something new - DKIM.

Then there is DNS ... an SMTP relay has to protect itself from SPAM/Bot usage.
Valid dependable/reliable servers that sendmail, probably have SPF records in DNS.

Does your domains?

If this used to work and now doesn't, do you have any message in your inbox that came from your moodle?   Look at the full header of that message ... from subject line up to the top of that message header you will see all the mail servers that message ran through to get to your inbox.

Sending email isn't simple and does require some digging.   If you can't do that, up to provider - one that is willing to help the customer and not reason that if one app can send then all should be able to send ... that's kinda a 'dodge' to me, cause, as we all know, a WordPress isn't a Moodle, and a Moodle isn't a WordPress ... neither of those are a Joomla or a Drupal either.

My 2 cents!
'SoS', Ken

回复Rich Solomon

Re: Office 365 SMTP and Moodle

Ken Task -
Particularly helpful Moodlers的头像
One other thought ... saw somewhere that Microsoft was going to drop support for older versions of TLS ... 1.3 or higher only.


Test your own server as well.

'SoS', Ken

回复Ken Task

Re: Office 365 SMTP and Moodle

Rich Solomon -
So in reply to a lot of this, we're running 4.2.2

The hosting provider is the "they". "They" support the virtual server, but not necessarily the configuration of the applications running on it. Using SMTP settings on Moodle, that are NOT associated with O365 work just fine. The O365 SMTP settings on a different application on the same server, work just fine as well. O365 SMTP settings in Moodle are not. There are two "applications" in the same domain. A website, and this Moodle install. The website uses the O365 SMTP settings just fine, and Moodle does not. So it's clearly more application configuration. As I certainly get that they are not the same application (many kinds of CMS's and LMS's), and that there are some nuances here with Moodle specifically. That's what I'm trying to investigate.

As far as caps, and spam awareness, there's *maybe* 1 or 2 emails a day that would be sent. This has never triggered any bot alarms or caps. The domain isn't new.

This might just be a dead end unfortunately. There's just too little information suggesting failure causes, and I've matched every setting that I have found in the forums. Seems like some have luck, and others don't.
回复Rich Solomon

Re: Office 365 SMTP and Moodle

Juan Antonio Moreno Carmona -
Particularly helpful Moodlers的头像
HI, Ken & Rich

Excuse my boldness, but on occasions I have had problems with adjusting Moodle email with O365, although I have always had success.

I would give the "email Test" plugin a try. Install it, set the debugging level to "developper". Then, go to "Site administration->Server->Email->Email Test" and try to send

an email to, for example, your own email account. You will be able to see the entire SMTP dialogue between the client (your Moodle) and the server (Office 365).

Maybe we can see some clue to the problem there.



I just ran a test right now on my system (moodle 4.1.5+) and I get the following:


Greetings and good luck.
回复Juan Antonio Moreno Carmona

Re: Office 365 SMTP and Moodle

Ken Task -
Particularly helpful Moodlers的头像
@Juan ...
No.  Please do 'hop in' here ... and take over.
Am not being helpful at all! 伤心

'SoS', Ken

回复Juan Antonio Moreno Carmona

Re: Office 365 SMTP and Moodle

Rich Solomon -
Thanks for the information!

Here's what I've learned so far...(thanks to the Email Test plugin!!!!!)

When we migrated our email to O365, the MS team changed an SPF record during that migration, that I didn't know about. Then the GoDaddy server ended up not allowing any outbound mail. GoDaddy support went and fixed the SPF record, and then began allowing outbound mail, but the changes may take a while to propagate. So I can try the O365 SMTP settings again later or tomorrow. For now though, mail is starting to flow just using PHPMailer.

I'm quite interested in getting O365 settings to work however, so I'll jump back into this soon.

Thank you, and please stand by as I'll be trying those settings again shortly!
回复Rich Solomon

Re: Office 365 SMTP and Moodle

Rich Solomon -
Should have had enough time to effect some changes, and it looks like a fix is needed in the CNAME? Here's the "name modified" log output.

2023-09-18 18:35:15 Connection: opening to smtp.office365.com:587, timeout=300, options=array()
2023-09-18 18:35:15 Connection: opened
2023-09-18 18:35:15 SERVER -> CLIENT: 220-XX.XXX.XXX.XX.host.SERVER.COM ESMTP Exim 4.96 #2 Mon, 18 Sep 2023 18:35:15 +0000
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
2023-09-18 18:35:15 CLIENT -> SERVER: EHLO www.sablealturafire.org
2023-09-18 18:35:15 SERVER -> CLIENT: 250--XX.XXX.XXX.XX.host.SERVER.COM Hello www.SOMEWHERE.org [2603:3:6100:e680::]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-PIPECONNECT
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2023-09-18 18:35:15 CLIENT -> SERVER: STARTTLS
2023-09-18 18:35:15 SERVER -> CLIENT: 220 TLS go ahead
2023-09-18 18:35:15 Connection failed. Error #2: stream_socket_enable_crypto(): Peer certificate CN=`-XX.XXX.XXX.XX.host.SERVER.COM' did not match expected CN=`smtp.office365.com' [/home/MOODLESITE/public_html/portal/lib/phpmailer/src/SMTP.php line 468]
2023-09-18 18:35:15 SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): Peer certificate CN=`-XX.XXX.XXX.XX.host.SERVER.COM' did not match expected CN=`smtp.office365.com'
2023-09-18 18:35:15 CLIENT -> SERVER: QUIT
2023-09-18 18:35:15 SERVER -> CLIENT: `
s DUD > 8 221 -XX.XXX.XXX.XX.host.SERVER.COM closing connection
2023-09-18 18:35:15 SMTP ERROR: QUIT command failed: `
s DUD > 8 221 -XX.XXX.XXX.XX.host.SERVER.COM closing connection
2023-09-18 18:35:15 Connection: closed
2023-09-18 18:35:15 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
other event data must be compatible with json encoding
line 747 of /lib/classes/event/base.php: call to debugging()
line 785 of /lib/classes/event/base.php: call to core\event\base->validate_before_trigger()
line 6341 of /lib/moodlelib.php: call to core\event\base->trigger()
line 214 of /local/mailtest/index.php: call to email_to_user()


Thanks to all for their eyes on this, and your help so far!


Rich
回复Rich Solomon

Re: Office 365 SMTP and Moodle

Ken Task -
Particularly helpful Moodlers的头像
3rd line down ... at tail end I see:
ESMTP Exim 4.96 #2
So you are running locally on server Exim?
and right under that:
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.

Wow!  You have an MS 'Team'?
Don't think this has anything to do with CNAME.
Your SPF record looks ok to me.
Uhhh ... your attempt to obsure (hide) your server ... was incomplete ... but good that you slipped up ... wouldn't have been able to check your SPF record then! 微笑

So suggest you check your EXIM setup!

'SoS', Ken

回复Ken Task

Re: Office 365 SMTP and Moodle

Ken Task -
Particularly helpful Moodlers的头像
One more additional request ... made earlier but guess you were either too frustrated or wrote it off as not pertaining to the issue ... even though it would help!

I asked if you would look at the full header of an old message that came from your moodle in your inbox.
Why?
From the subject line upwards in the full header you will see 'Received by' lines ... those are mail servers that message went through to get to your inbox.   Don't think you've changed the mail service on your server ... it's still EXIM ... and all moodles use phpmailer - those 2 you should see in the full header.

Oh, well, either do or don't (and you'll never know ... it's all just 'magic' then)! 微笑

'SoS', Ken




回复Ken Task

Re: Office 365 SMTP and Moodle

Rich Solomon -
We have a hosted 365 solution.  So yes, there is a dedictaed MS 365 support team offered through the government vendor to support 365.


We have a GoDaddy VPS that our webaite and Moodle run on.  There is a GoDaddy VPS team that assists with that server.

No one supports any apps on the server, and np one directly suppots the outside SMTP connection.


Running just via PHP, and through the servers own SMTP relay, mail works fine.  This is a connection to O365 glitch.  Dpnt know anything about Exim, but the VPS folks said its all good on their end.

回复Rich Solomon

Re: Office 365 SMTP and Moodle

Juan Antonio Moreno Carmona -
Particularly helpful Moodlers的头像
Hi Rich.

I'm not entirely sure, but do you have a WHM/CPanel to manage your website and moodle?
So I think "SMTP Restrictions" is enabled.

Try to follow the instructions on this page to disable "SMTP Restrictions" and try again to send email.

Greetings.
回复Rich Solomon

Re: Office 365 SMTP and Moodle

Ken Task -
Particularly helpful Moodlers的头像
I didn't strike a nerve, did I?   Not the intent.   But interesting to hear you appear to be the only one mananging anything in your setup! 微笑

Still not wanting to look at full header of a past message ... like I said, Oh well....

I don't get it ... it works without 0365 smtp relay but you want it to work with 0365 because you have a contract (and a gov't one at that).   Makes me wonder ... Why?   but that's a question I really don't want to hear the answer/justification!

Take it the 'EXIM team' has seen what you shared here.
'Good on their end' ... hmmmm, since you appear to have full access to your GD VPS, it means you should be able to look at mail server logs that should be there since your server does run EXIM ... full blown server.

Again ... "I don't get it!" ...  Just use what works!
Ok, not being helpful, so I'll back out of here ... wish you luck and let  someone else attempt to help!

'SoS', Ken

回复Ken Task

Re: Office 365 SMTP and Moodle

Rich Solomon -
NO of course you didn't strike a nerve.  You're one of the most helpful people out here in these forums, so I pay attention!  I just don't always have all of the answers...I'll try...

I just never had a full header of a past message.  It had never worked properly.

It wasn't working at all anymore after some changes that the O365 group made on the SPF after we migrated.  So, that's what started the forum post.  Past history incoming...

We ran our own physical web server, and our own physical Exchange server (on old SBS 2011).  These hardware pieces became a bit old, and too difficult to continue to maintain. We migrated our website and Moodle install to a virtual server.  Had to rebuild a new website, and rebuild the Moodle site.  Nothing migrated like it should have.  This server came online, and we had cobbled pieces of it working.  A week later, we migrated over to Office 365.  This broke a few things as our domain was now split a bit.

Anyway, moving along...
As now no email was working from Moodle was working, and I was able to successfully get O365 working via SMTP with our WP site, I dove headfirst into trying to get O365 to be the relay for Moodle. It seemed that plenty of people had made it successful, and I've got an email user and account set up on O365 to be able to respond easily.  So, maybe I was a little stubborn on wanting to get O365 working when there was another solution, but that's because it was originally all broken, and then I became a little possessed with trying to figure out why.

At this point, I am using just what works.  But it's frustrating when you can't figure out why it isn't working.  I'm not a developer, I'm not behind a computer all day.  I'm a firefighter, who switched careers from being a network engineer 15 years ago when Frame Relay was giving way to ATM, and we all wrote HTML by hand.  That life, and that I've stayed a bit connected to IT makes me server admin, developer, and Tier1-4 support for all of this. I just don't always have the time or resources to do all of this the way others can.  I'm just supporting my small 30-person fire department.

Ultimately I ask that you'd never back out.  Again, you're one of the best resources out here.  You answer thousands of things, so you may not know this...but out of my solutions out here, you're at the root of 95% of them, and some critical solutions at that!
回复Rich Solomon

Re: Office 365 SMTP and Moodle

Ken Task -
Particularly helpful Moodlers的头像
Sent you a priviate message on this system ... little Bell icon upper right of screen when you are looking at your thread in this forum.
That PM has my cell-phone number + another off forum email address for us to take the conversation off this public forum.
There are just too many questions and information of a sensitive nature that we need to exchange.

Am in San Antonio, Tx .. Central Daylight Savings Time so if you call my cell please keep TZ differences in mind! 微笑

'SoS', Ken

回复Ken Task

Re: Office 365 SMTP and Moodle

Rich Solomon -
Didn't see a new message, but I happened to see one from back in March that you sent me on another issue. Sent you an offsite email.
回复Ken Task

RESOLVED - Re: Office 365 SMTP and Moodle

Ken Task -
Particularly helpful Moodlers的头像
In OP's setup case ... no SMTP setup needed as mx record for the domain pointed to where their mail was anyway! 微笑

'SoS', Ken