Logging for SMTP emails

4 posts by 2 authors in: Forums > CMS Builder
Last Post: December 17   (RSS)

I have a site where the outgoing mail settings are set to send via a third party SMTP host.  Emails sent this way are logged in the CMS Outgoing Mail and also in the log of the third party SMTP host.

This is working in general but occassionally an email is sent which is then logged within the CMS but not at the third party SMTP host.

Is there any more verbose logging that we can enable for SwiftMailer to work out why some emails are failing?

Thanks, Paul.

Hi Paul, 

We switched from SwiftMailer to PHP Mailer a couple of years ago.  Are you on a recent CMSB version? Or can you upgrade if needed?

Let me know which CMSB version you're on, and we can figure out how to add logging so you can track it down.

Dave Edis - Senior Developer
interactivetools.com

Hi Paul, 

Swift Mailer stopped being maintained Nov, 2021: https://swiftmailer.symfony.com/docs/introduction.html

I think we originally switched away from it when there was a mail sending problem and no chance of fixes.  Upgrading to the latest CMSB (and new mailer) may fix any issues you're having now.

So ideally it will just work, and you wouldn't need to add any logging at all, but to answer your question, you can enable verbose debugging with the SMTPDebug property.  Here are some pure PHP examples (would need to be adapted for CMSB):

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;

$mail = new PHPMailer();
$mail->SMTPDebug = SMTP::DEBUG_SERVER;  // or use integer values below

Debug Levels:
- 0 / SMTP::DEBUG_OFF - No output (default)
- 1 / SMTP::DEBUG_CLIENT - Client messages only
- 2 / SMTP::DEBUG_SERVER - Client and server messages (most useful)
- 3 / SMTP::DEBUG_CONNECTION - Plus connection info
- 4 / SMTP::DEBUG_LOWLEVEL - All messages including data

Custom Debug Output Handler:
$mail->Debugoutput = function($str, $level) {
    error_log("PHPMailer [$level]: $str");
};

Or use built-in handlers:
$mail->Debugoutput = 'html';   // HTML formatted
$mail->Debugoutput = 'echo';   // Plain text (default)
$mail->Debugoutput = 'error_log'; // Send to PHP error log

For troubleshooting SMTP issues, DEBUG_SERVER (level 2) is typically sufficient to see the conversation between your server and the mail server.

However, in recent versions under: Admin > Email Settings, there's a form to send a test email, and it will show you all the debug output there as well.

There are also some links in that menu to free services where you can send an email through the UI for complete deliverability analysis (SPF, DKIM, DMARC, and blacklists).

Hope that helps, let me know any questions.

Dave Edis - Senior Developer
interactivetools.com