[MGNLMAIL-77] Add possibility for SMTP Session debugging Created: 21/Sep/16  Updated: 17/May/22  Resolved: 10/Jun/20

Status: Closed
Project: Magnolia Mail Module
Component/s: None
Affects Version/s: 5.5.4
Fix Version/s: 5.5.5

Type: Improvement Priority: Neutral
Reporter: Stefan Baur Assignee: Federico Grilli
Resolution: Done Votes: 0
Labels: maintenance, quickwin
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Cloners
Relates
relates to MGNLMAIL-104 Unable to send email through Gmail Closed
relation
is related to MGNLMAIL-127 Send SMTP Session debugging to log Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Documentation update required:
Yes
Date of First Response:
Visible to:
Michael Rauch
Sprint: Maintenance 11
Story Points: 0.5

 Description   

Hi

I was tracking down an SMTP issue and missed the possibility to put the java mail Session into debug mode. I think it would be straight forward to implement a flag in the mail module config and using it when the session object is create in info.magnolia.module.mail.MailTemplate#initSession

Just call session.setDebug() before returning.

Example debug output:

DEBUG: setDebug: JavaMail version 1.4.1ea-SNAPSHOT
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "SOMEHOST", port 25, isSSL false
220 smtp-relay.gmail.com ESMTP c202sm3300653wmd.2 - gsmtp
DEBUG SMTP: connected to host "SOMEHOST", port: 25

EHLO c13434.local
250-smtp-relay.gmail.com at your service, [95.143.54.50]
250-SIZE 157286400
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "157286400"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<test@example.com>
550-5.7.0 Mail relay denied [95.143.54.50]. Invalid credentials for relay for
550-5.7.0 one of the domains in: example.com (as obtained from helo and
550-5.7.0 mail-from).
550-5.7.0 Email is being sent from a domain or IP address which isn't registered
550-5.7.0 in Google Apps account. Please login to your Google Apps account and
550-5.7.0 verify that your sending device IP address has been registered within
550-5.7.0 Google Apps SMTP Relay Settings. For more information, please visit



 Comments   
Comment by Richard Gange [ 04/May/20 ]

By setting info.magnolia.module.mail.MailTemplate to DEBUG you can turn on javax.mail.Session debugging.

Changed to a configuration parameter on the smtp config node. debug=true

Example output:

2020-05-04 18:07:25,324 DEBUG info.magnolia.module.mail.MailTemplate            : Setting javax.mail.Session to debug
DEBUG: setDebug: JavaMail version 1.6.2
2020-05-04 18:07:25,329 DEBUG info.magnolia.module.mail.templates.MgnlEmail     : Set attachments [0] for mail: [info.magnolia.module.mail.templates.impl.FreemarkerEmail]
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=smtp.mail.ch, user=magnolia.cms, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.mail.ch", port 465, isSSL true
220 smtp01.mail.ch ESMTP
DEBUG SMTP: connected to host "smtp.mail.ch", port: 465
EHLO localhost
250-smtp01.mail.ch
250-PIPELINING
250-SIZE 160000000
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250 DSN
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "160000000"
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "AUTH=PLAIN", arg "LOGIN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: protocolConnect login, host=smtp.mail.ch, user=magnolia.cms, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2 
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<magnolia.cms@mail.ch>
250 2.1.0 Ok
RCPT TO:<magnolia.cms@mail.ch>
250 2.1.5 Ok
RCPT TO:<magnolia.cms@mail.ch>
250 2.1.5 Ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   magnolia.cms@mail.ch
DEBUG SMTP:   magnolia.cms@mail.ch
DATA
354 End data with <CR><LF>.<CR><LF>
Date: Mon, 4 May 2020 18:07:25 +0200 (CEST)
From: magnolia.cms@mail.ch
To: magnolia.cms@mail.ch, magnolia.cms@mail.ch
Message-ID: <1617772963.1.1588608445333@localhost>
Subject: This is a test email for freemarker template
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<h1></h1>
<img src="cid:0001"/>

This is the path that has been changed: 

.
250 2.0.0 Ok: queued as CCE8A10036F
DEBUG SMTP: message successfully delivered to mail server
QUIT
221 2.0.0 Bye
2020-05-04 18:07:26,080 INFO  fo.magnolia.module.mail.handlers.SimpleMailHandler: Mail has been sent to: [magnolia.cms@mail.ch, magnolia.cms@mail.ch]
Comment by Richard Gange [ 10/Jun/20 ]

jlegendre I'll do the documentation update when this is released.

Comment by Richard Gange [ 12/Aug/20 ]

Added: https://documentation.magnolia-cms.com/display/DOCS62/Mail#Mail-SMTPSessiondebugging

Generated at Mon Feb 12 06:03:24 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.