Apr 18, 2018

Windows Moodle Email STARTTLS error - fixed!

THE FOLLOWING APPLIES TO AN OLDER VERSION OF MOODLE. YOUR MILEAGE MAY VARY:

The Windows Moodle package is a great, easy way to get Moodle up and running on a Windows machine. The downside? Setting up email is a pain in the rump.  It didn't have to be.

The problem we had was one where the SMTP server would respond with "STARTTLS" errors.  I spent a LOT of time editing my sendmail.ini file (and even installed the latest sendmail for Windows).  Nothing would cure the problem.

I started poking around the Moodle forums, and while they are generally helpful for many things, the STARTTLS error is not one of them.  However, *nix forums ARE helpful.. sorta.

In the Moodle directory on your Windows server, you need to edit the class.phpmailer.php file *in addition* to setting up sendmail as your mailer. Why? Who the heck knows.  In any case, here is what is working for us, so I hope it helps you!

FIRST: MOODLE ADMIN
   Site Administration > Plugins > Message Outputs > EMAIL
   Type your SMTP host, username, password as needed (you NEED the SMTP host, the others may be optional based on YOUR mail handler/mail host. Google requires it)
   Type noreply@yourdomain.com for the no-reply address.  Substitute your REALY domain for the "yourdomain" part there!
SECOND: SENDMAIL
   Download the latest SENDMAIL to your Moodle server and unzip it to X:\moodle\server\sendmail (substitute the actual driver letter for X there!)
   On your server, go to your X:\moodle\server\sendmail folder
   EDIT the sendmail.ini file:
       smtp_port=25 (usually leave this as is)
       smtp_ssl=auto (could specify TLS here)
       auth_username=valid.user@yourdomain.com
       auth_password=ValidUsersPa$$word
       hostname=yourdomain.com
THIRD: PHPMAILER
   Navigate to X:\moodle\server\moodle\lib\phpmailer on your server (again, substitue your actual location for X)
   EDIT the class.phpmailer.php file (use WordPad)
   SEARCH for TLS
   A few lines down, edit the "SMTPSecure" line:
       public $SMTPSecure = 'tls';
   DO NOT CHANGE ANYTHING ELSE IN THIS FILE!!
FOURTH: PHP.INI
   Navigate to X:\moodle\server\php
   EDIT the php.ini file:
       SMTP = yourmailserver.com
       smtp_port = 25
       sendmail_from = valid.user@yourdomain.com
       sendmail_path = "X:\moodle\server\sendmail\sendmail.exe -t"
   SAVE the file.
Once you have done these, you need to STOP MOODLE then START MOODLE in order for the system to take the changes.
Moodle email may not run by itself.  You can use Task Scheduler in order to call the CRON.PHP page in your Moodle environment. Or you can use MoodleCron for Windows. Very easy to use!
NOTE: Use at your own risk. This worked for me. I hope it works for you, but I will not be held liable for anything that goes wrong with your server/environment/etc.
NOTE: The above steps may be a bit of overkill.  Some steps may not be required in order to get email working in Moodle. I have not gone back to determine just which step(s) worked.  Once it was fixed, I didn't break it again.

No comments:

Post a Comment