Problems with Moodle sending mails

Problems with Moodle sending mails

by stefan weber -
Number of replies: 3
Picture of Plugin developers

We are in the process of migrating to a new VM, and have set up a test server there, and I cannot get my new test site to send mails.

  • The test server is running the exact same Moodle version (3.6.7) with the same config and database dump as my old test server.
  • config.php has "divertallemailsto" set on both servers.
  • command-line "sendmail" works on both servers
  • a php script with the command "mail" works on both servers
  • sending messages to users or posting in a forum does not create e-Mails on the new test server, only on the old one
  • if i create a forum post to trigger e-mails, and run the cron job with cron debugging set to true, i get this error:

* line 81 of /admin/cron.php: call to cron_run()
post 105337: test debx mail 12:15
Processing user 16905
Sending <pre>
</pre><pre>
2020-01-07 11:16:01	Connection: opening to localhost:25, timeout=300, options=array()
2020-01-07 11:16:01	Connection failed. Error #2: stream_socket_client(): unable to connect to localhost:25 (Connection refused) [/var/www/moodle/lib/phpmailer/src/SMTP.php line 319]
2020-01-07 11:16:01	SMTP ERROR: Failed to connect to server: Connection refused (111)
2020-01-07 11:16:01	SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Error: lib/moodlelib.php email_to_user(): SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
</pre>++ Error calling message processor email ++

I ran out of ideas as to what could be the problem, any help would be appreciated

Average of ratings: -
In reply to stefan weber

Re: Problems with Moodle sending mails

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi Stefan

You wrote:
> command-line "sendmail" works on both servers
> ...
> 2020-01-07 11:16:01 Connection: opening to localhost:25, timeout=300, options=array()

Both can't be true at the same time. What was the "command-line sendmail"? Something like this?

$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 your.domain.com ESMTP Postfix (Debian/GNU)
EHLO gugus.da
250-your.domain.com
...
250 CHUNKING
MAIL FROM: gugus@dada.com
250 2.1.0 Ok
RCPT TO: avalidemail@example.com
250 2.1.5 Ok
DATA
354 End data with .testing
.

250 2.0.0 Ok: queued as 2A83F406868D
quit
221 2.0.0 Bye


P.S. I don't think the cause of you problem is not the same as OP. Suggest the moderator to split it.
In reply to stefan weber

Re: Problems with Moodle sending mails

by stefan weber -
Picture of Plugin developers
turns out the problem was on the mail server itself, where both moodle test servers relayed the mails to. Unfortunately, I couldnt get a more detailed description as to what exactly was the problem from our server admins smile.
In reply to stefan weber

Re: Problems with Moodle sending mails

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
You say, Site administration > Server > Email > Outgoing mail configuration were all empty, means the mails were spooled to a local "sendmail" (Exim, Postfix) and relayed to them to your institutions SMTP server. There was a misunderstanding in that link?