Skip to content
Advertisement

JavaMail sends no content with SMTP, sends “QUIT” and hangs

I’m trying to use JavaMail 1.6 to send an email to a local MailHog SMTP server in Java 8. The code is:

JavaScript

When the code is ran, it will start and establish a session with the server, and step through SMTP until it’s supposed to send data. After this, it sends QUITrn and hangs, not sending any content.

MailHog logs:

JavaScript

Java output:

JavaScript

Looking around, I can find a few references of JavaMail hanging while sending mail, but none of them seem to hang at this part of the session. It seems like it should be a misconfiguration related to message.setText. However, I get the same behavior when using message.setContent(body, "text/plain"), using MimeMultipart and adding a MimeBodyPart with the content, and also when using a DataHandler. Furthermore, if it is a misconfiguration of the content, I find it weird that it’s sending a QUIT immediately without first terminating the DATA. As far as I know, a normal exchange would look something like:

JavaScript

Advertisement

Answer

Answering my own question:

JavaMail (Maven package javax.mail/javax.mail-api) was moved to Jakarta Mail (com.sun.mail/jakarta.mail). I’m not really sure what’s wrong with the old package, but once I updated the appropriate maven dependency from

JavaScript

to

JavaScript

The issue resolved itself with no further code changes needed.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement