Reputation: 593
What is the proper configuration for Mailgun to be used with Moodle? I am using the Bitnami Moodle image on Google Cloud.
SMTP Hosts: smtp.mailgun.org
SMTP Security: none
SMTP Auth Type: Login
I receive this error message.
Error sending password change confirmation email
More information about this error
Debug info: Error code: cannotmailconfirm Stack trace: line 495 of /lib/setuplib.php: moodle_exception thrown line 110 of /login/lib.php: call to print_error() line 81 of /login/forgot_password.php: call to core_login_process_password_reset_request() Output buffer:
2016-11-18 14:21:25 Connection: opening to smtp.mailgun.org:25, timeout=300, options=array ( ) 2016-11-18 14:23:32 SMTP ERROR: Failed to connect to server: Connection timed out (110) 2016-11-18 14:23:32 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Upvotes: 1
Views: 1751
Reputation: 1046
I just did that in a server on digital ocean. So here the solution:
The trick here is port 587. I tried everything but just this worked. As a bonus, if you have ssh access to your server you can send emails form terminal with:
./swaks --auth \
--server smtp.mailgun.org:587 \
--au postmaster@<yourdomain> \
--ap <smtpcredential> \
--to [email protected] \
--h-Subject: "Teste Moodle" \
--body 'Testing some Mailgun awesomness!'
And, as you are running moodle, if you want to do the same with php
:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mailgun.org:587'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = '<your credetials>'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, only 'tls' is accepted
$mail->From = '[email protected]';
$mail->FromName = 'You';
$mail->addAddress('[email protected]'); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->Subject = 'PHP subject';
$mail->Body = 'Email from php!';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
Upvotes: 0
Reputation: 899
Google Compute Engine does not allow outbound connections on ports 25, 465, and 587. By default, these outbound SMTP ports are blocked because of the large amount of abuse these ports are susceptible to.
Port 25 outbound is blocked on Google Cloud. Mailgun mirrors 587, on port 2525 - so try using port 2525.
As a quick test you could also try telnetting from the command line to check connectivity, like this:
> telnet smtp.mailgun.org 2525
Upvotes: 1
Reputation: 830
You should attempt to use port 465
instead of port 25
as well as setting encryption to SSL
.
I haven't used moodle personally but I believe you can do it like this:
UPDATE mdl_config SET value='ssl://smtp.mailgun.org:465' WHERE name='smtphosts';
Upvotes: 0