I'm debugging mail services for a remote application server. They are served by a plesk managed mailserver. Since the plesk managed VM is used for mailserver purpose only, for the interested domain the hosting type is set to no hosting, and the website status is set to suspended. I have proper MX records in place on my Route53 zones, together with proper A record for the mailserver.example.com hostname.
On the app server I have a debug page with the following code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require '../../phpmailer/PHPMailer-master/src/Exception.php';
require '../../phpmailer/PHPMailer-master/src/PHPMailer.php';
require '../../phpmailer/PHPMailer-master/src/SMTP.php';
date_default_timezone_set('Etc/UTC');
$smtp = new SMTP;
$smtp->do_debug = SMTP:: DEBUG_CONNECTION;
$mail->SMTPDebug = SMTP:: DEBUG_SERVER;
try {
//Connect to an SMTP server
if (!$smtp->connect('mailserver.example.com', 25)) {
throw new Exception('Connect failed');
}
//Say hello
if (!$smtp->hello(gethostname())) {
throw new Exception('EHLO failed: ' . $smtp->getError()['error']);
}
//Get the list of ESMTP services the server offers
$e = $smtp->getServerExtList();
//If server can do TLS encryption, use it
if (is_array($e) && array_key_exists('STARTTLS', $e)) {
$tlsok = $smtp->startTLS();
if (!$tlsok) {
throw new Exception('Failed to start encryption: ' . $smtp->getError()['error']);
}
//Repeat EHLO after STARTTLS
if (!$smtp->hello(gethostname())) {
throw new Exception('EHLO (2) failed: ' . $smtp->getError()['error']);
}
//Get new capabilities list, which will usually now include AUTH if it didn't before
$e = $smtp->getServerExtList();
}
//If server supports authentication, do it (even if no encryption)
if (is_array($e) && array_key_exists('AUTH', $e)) {
if ($smtp->authenticate('existingmailuser', 'mailuserpassword')) {
echo 'Connected ok!';
} else {
throw new Exception('Authentication failed: ' . $smtp->getError()['error']);
}
}
} catch (Exception $e) {
echo 'SMTP error: ' . $e->getMessage(), "\n";
}
//Whatever happened, close the connection.
$smtp->quit();
?>
When I call this debug page I get this result:
2020-05-28 18:45:20 Connection: opening to mailserver1.example.com:25, timeout=30, options=array() 2020-05-28 18:45:20 Connection: opened 2020-05-28 18:45:20 SERVER -> CLIENT: 220 mailserver1.example.com ESMTP Postfix 2020-05-28 18:45:20 CLIENT -> SERVER: EHLO mailserver1 2020-05-28 18:45:20 SERVER -> CLIENT: 250-mailserver1.example.com 250-PIPELINING 250-SIZE 20480000 250-ETRN 250-STARTTLS 250-AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250-SMTPUTF8 250 CHUNKING 2020-05-28 18:45:20 CLIENT -> SERVER: STARTTLS 2020-05-28 18:45:20 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS 2020-05-28 18:45:20 CLIENT -> SERVER: EHLO thor02 2020-05-28 18:45:20 SERVER -> CLIENT: 250-mailserver1.example.com 250-PIPELINING 250-SIZE 20480000 250-ETRN 250-AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250-SMTPUTF8 250 CHUNKING 2020-05-28 18:45:20 CLIENT -> SERVER: AUTH CRAM-MD5 2020-05-28 18:45:20 SERVER -> CLIENT: 334 PDE5MjUxODYxODIuMTM2MzMzMTBAdmFsY2hpcmlhMDEubmF2aWdhcmVuZWNlc3NlLml0Pg== 2020-05-28 18:45:20 CLIENT -> SERVER: [credentials hidden] 2020-05-28 18:45:20 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: authentication failure 2020-05-28 18:45:20 SMTP ERROR: Username command failed: 535 5.7.8 Error: authentication failed: authentication failure SMTP error: Authentication failed: Username command failed 2020-05-28 18:45:20 CLIENT -> SERVER: QUIT 2020-05-28 18:45:20 SERVER -> CLIENT: 221 2.0.0 Bye 2020-05-28 18:45:20 Connection: closed
On the mailserver side, the mail settings are set as follows:
Postfix
Send from domain IP addresses
Enable mail autodiscover
Relaying: authorization required SMTP
DMARC
DKIM
SPF
Can you give me a help to make things work?
Thank you in advance.
On the app server I have a debug page with the following code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require '../../phpmailer/PHPMailer-master/src/Exception.php';
require '../../phpmailer/PHPMailer-master/src/PHPMailer.php';
require '../../phpmailer/PHPMailer-master/src/SMTP.php';
date_default_timezone_set('Etc/UTC');
$smtp = new SMTP;
$smtp->do_debug = SMTP:: DEBUG_CONNECTION;
$mail->SMTPDebug = SMTP:: DEBUG_SERVER;
try {
//Connect to an SMTP server
if (!$smtp->connect('mailserver.example.com', 25)) {
throw new Exception('Connect failed');
}
//Say hello
if (!$smtp->hello(gethostname())) {
throw new Exception('EHLO failed: ' . $smtp->getError()['error']);
}
//Get the list of ESMTP services the server offers
$e = $smtp->getServerExtList();
//If server can do TLS encryption, use it
if (is_array($e) && array_key_exists('STARTTLS', $e)) {
$tlsok = $smtp->startTLS();
if (!$tlsok) {
throw new Exception('Failed to start encryption: ' . $smtp->getError()['error']);
}
//Repeat EHLO after STARTTLS
if (!$smtp->hello(gethostname())) {
throw new Exception('EHLO (2) failed: ' . $smtp->getError()['error']);
}
//Get new capabilities list, which will usually now include AUTH if it didn't before
$e = $smtp->getServerExtList();
}
//If server supports authentication, do it (even if no encryption)
if (is_array($e) && array_key_exists('AUTH', $e)) {
if ($smtp->authenticate('existingmailuser', 'mailuserpassword')) {
echo 'Connected ok!';
} else {
throw new Exception('Authentication failed: ' . $smtp->getError()['error']);
}
}
} catch (Exception $e) {
echo 'SMTP error: ' . $e->getMessage(), "\n";
}
//Whatever happened, close the connection.
$smtp->quit();
?>
When I call this debug page I get this result:
2020-05-28 18:45:20 Connection: opening to mailserver1.example.com:25, timeout=30, options=array() 2020-05-28 18:45:20 Connection: opened 2020-05-28 18:45:20 SERVER -> CLIENT: 220 mailserver1.example.com ESMTP Postfix 2020-05-28 18:45:20 CLIENT -> SERVER: EHLO mailserver1 2020-05-28 18:45:20 SERVER -> CLIENT: 250-mailserver1.example.com 250-PIPELINING 250-SIZE 20480000 250-ETRN 250-STARTTLS 250-AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250-SMTPUTF8 250 CHUNKING 2020-05-28 18:45:20 CLIENT -> SERVER: STARTTLS 2020-05-28 18:45:20 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS 2020-05-28 18:45:20 CLIENT -> SERVER: EHLO thor02 2020-05-28 18:45:20 SERVER -> CLIENT: 250-mailserver1.example.com 250-PIPELINING 250-SIZE 20480000 250-ETRN 250-AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250-SMTPUTF8 250 CHUNKING 2020-05-28 18:45:20 CLIENT -> SERVER: AUTH CRAM-MD5 2020-05-28 18:45:20 SERVER -> CLIENT: 334 PDE5MjUxODYxODIuMTM2MzMzMTBAdmFsY2hpcmlhMDEubmF2aWdhcmVuZWNlc3NlLml0Pg== 2020-05-28 18:45:20 CLIENT -> SERVER: [credentials hidden] 2020-05-28 18:45:20 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: authentication failure 2020-05-28 18:45:20 SMTP ERROR: Username command failed: 535 5.7.8 Error: authentication failed: authentication failure SMTP error: Authentication failed: Username command failed 2020-05-28 18:45:20 CLIENT -> SERVER: QUIT 2020-05-28 18:45:20 SERVER -> CLIENT: 221 2.0.0 Bye 2020-05-28 18:45:20 Connection: closed
On the mailserver side, the mail settings are set as follows:
Postfix
Send from domain IP addresses
Enable mail autodiscover
Relaying: authorization required SMTP
DMARC
DKIM
SPF
Can you give me a help to make things work?
Thank you in advance.
Last edited: