Log4j2 SMTP-Appender "Must issue a STARTTLS command first" - java

I am trying to send log entries with severity "error" via email in java.
In my log4j2.xml file I have the following SMTP appender:
<SMTP>
name="Mail"
subject="Error Log"
to="receiver#domain.com"
from="sender#domain.com"
smtpHost="SMTP-Host"
smtpPort="587"
smtpPassword="[password]"
smtpUsername="email#domain.com"
smtpDebug="true"
ignoreExceptions="false"
bufferSize="4"
smtpProtocol="smtp">
</SMTP>
But when I run my programm (which consists of a main logging a string) the following error occurs:
DEBUG: setDebug: JavaMail version 1.4.7
13:13:44.469 [main] ERROR Main - Test Error
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "SMTP-Host", port 587, isSSL false
220 SMTP-Host ESMTP Postfix (Debian/GNU)
DEBUG SMTP: connected to host "SMTP-Host", port: 587
EHLO MAXPC
250-SMTP-Host
250-PIPELINING
250-SIZE 52428800
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<sender#domain.com>
530 5.7.0 Must issue a STARTTLS command first
DEBUG SMTP: got response code 530, with response: 530 5.7.0 Must issue a STARTTLS command first
RSET
530 5.7.0 Must issue a STARTTLS command first
DEBUG SMTP: MessagingException while sending, THROW:
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.logging.log4j.core.net.SmtpManager.sendMultipartMessage(SmtpManager.java:257)
at org.apache.logging.log4j.core.net.SmtpManager.sendEvents(SmtpManager.java:172)
at org.apache.logging.log4j.core.appender.SmtpAppender.append(SmtpAppender.java:181)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:464)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:448)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:431)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:406)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2170)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2125)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2108)
at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2007)
at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1866)
at org.apache.logging.slf4j.Log4jLogger.error(Log4jLogger.java:299)
at Main.main(Main.java:8)
QUIT
221 2.0.0 Bye
2019-03-03 13:13:49,204 main ERROR SmtpManager SMTP:848b9401aab8a35f62b00f0dbdf21fd4 Caught exception while sending e-mail notification.: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.logging.log4j.core.net.SmtpManager.sendMultipartMessage(SmtpManager.java:257)
at org.apache.logging.log4j.core.net.SmtpManager.sendEvents(SmtpManager.java:172)
at org.apache.logging.log4j.core.appender.SmtpAppender.append(SmtpAppender.java:181)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:464)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:448)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:431)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:406)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2170)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2125)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2108)
at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2007)
at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1866)
at org.apache.logging.slf4j.Log4jLogger.error(Log4jLogger.java:299)
at Main.main(Main.java:8)
2019-03-03 13:13:49,206 main ERROR An exception occurred processing Appender Mail org.apache.logging.log4j.LoggingException: Error occurred while sending email
at org.apache.logging.log4j.core.net.SmtpManager.sendEvents(SmtpManager.java:175)
at org.apache.logging.log4j.core.appender.SmtpAppender.append(SmtpAppender.java:181)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:464)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:448)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:431)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:406)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2170)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2125)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2108)
at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2007)
at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1866)
at org.apache.logging.slf4j.Log4jLogger.error(Log4jLogger.java:299)
at Main.main(Main.java:8)
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.logging.log4j.core.net.SmtpManager.sendMultipartMessage(SmtpManager.java:257)
at org.apache.logging.log4j.core.net.SmtpManager.sendEvents(SmtpManager.java:172)
... 18 more
Exception in thread "main" org.apache.logging.log4j.core.appender.AppenderLoggingException: An exception occurred processing Appender Mail
at org.apache.logging.log4j.core.appender.DefaultErrorHandler.error(DefaultErrorHandler.java:75)
at org.apache.logging.log4j.core.config.AppenderControl.handleAppenderError(AppenderControl.java:165)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:158)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:464)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:448)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:431)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:406)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2170)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2125)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2108)
at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2007)
at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1866)
at org.apache.logging.slf4j.Log4jLogger.error(Log4jLogger.java:299)
at Main.main(Main.java:8)
Caused by: org.apache.logging.log4j.LoggingException: Error occurred while sending email
at org.apache.logging.log4j.core.net.SmtpManager.sendEvents(SmtpManager.java:175)
at org.apache.logging.log4j.core.appender.SmtpAppender.append(SmtpAppender.java:181)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
... 16 more
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.logging.log4j.core.net.SmtpManager.sendMultipartMessage(SmtpManager.java:257)
at org.apache.logging.log4j.core.net.SmtpManager.sendEvents(SmtpManager.java:172)
... 18 more
As far as I understand the programm can establish a connection to the server but then Must issue a STARTTLS command first this happens. Can someone explain to me what that means and how to fix it?
When I searched for the error I got a few posts with similar problems but not with log4j2 but with java.mail and they didn't helped me.
I tried using smtpPort="465" and smtpProtocol="smtps" but in both cases the connection got refused.
I have no more new ideas and am grateful for everyone who helps me.

I had the same issue and it looks like log4j2 is not capable of handling STARTTLS. Fortunately log4j uses the system properties when creating the mail session. So my fix is using
smtpProtocol="smtp"
for the SMTP appender and setting the system property
mail.smtp.starttls.enable=true
on the command line to activate STARTTLS for the mail session. You could alternatively use
System.setProperty("mail.smtp.starttls.enable", "true")
in your application code.

Related

Jmeter+Jenkins+File not found exception

// **Am running a meter script integrated with jenkins,when trying to send report it complains about "file not found exception"
have tried it locally it works fine but once moved on to the server getting the error.
have tried getting from workspace, it creates folders but doesn't have the file dropped and am using extent reporting any sujjestions/inputs is really appreciated
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: protocolConnect login, host=smtp.googlemail.com, user=rohith#cowboyaliens.com, password=
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:
250 2.1.0 OK w2-v6sm5908675wre.57 - gsmtp
RCPT TO:
250 2.1.5 OK w2-v6sm5908675wre.57 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: rohith#cowboyaliens.com
DATA
354 Go ahead w2-v6sm5908675wre.57 - gsmtp
DEBUG SMTP: IOException while sending, closing, THROW:
java.io.FileNotFoundException: /Users/alienbuilder/.jenkins/workspace/Sling-API-Automation/Sling/Report.html (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.(FileInputStream.java:138)
at javax.activation.FileDataSource.getInputStream(FileDataSource.java:97)
at javax.activation.DataHandler.writeTo(DataHandler.java:305)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1692)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:996)
at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:561)
at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:84)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889)
at javax.activation.DataHandler.writeTo(DataHandler.java:317)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1692)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1913)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1315)
at org.apache.jmeter.protocol.smtp.sampler.protocol.SendMailCommand.execute(SendMailCommand.java:303)
at org.apache.jmeter.protocol.smtp.sampler.SmtpSampler.executeMessage(SmtpSampler.java:169)
at org.apache.jmeter.protocol.smtp.sampler.SmtpSampler.sample(SmtpSampler.java:146)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:491)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:425)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:254)
at java.lang.Thread.run(Thread.java:748)
summary + 1 in 00:00:05 = 0.2/s Avg: 4262 Min: 4262 Max: 4262 Err: 1 (100.00%) Active: 0 Started: 1 Finished: 1
summary = 5 in 00:00:35 = 0.1/s Avg: 6944 Min: 2 Max: 30225 Err: 2 (40.00%)
Tidying up ... # Wed Oct 24 15:00:34 SAST 2018 (1540386034868)
... end of run
Archiving artifacts
Email was triggered for: Always
Sending email for trigger: Always
Sending email to: rohith#cowboyaliens.com rohithreddy.polusani#absa.co.za
Connection error sending email, retrying once more in 10 seconds...
Connection error sending email, retrying once more in 10 seconds...
Failed after second try sending email
Finished: SUCCESS

Send e-mail with Java using hotmail account

I'm doing a web application for send e-mails with a hotmail account. This is my code:
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "smtp.live.com");
props.put("mail.smtp.auth", true);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.user", "mail#hotmail.com");
props.put("mail.smtp.pwd", pass);
props.put("mail.debug", true);
props.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(props);
session.setDebug(true);
try {
MimeMessage mimeMessage = new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress("othermail#otherserver.com"));
mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress("mail#hotmail.com"));
mimeMessage.setSubject(subject);
mimeMessage.setContent(message, "text/html; charset=UTF-8");
mimeMessage.setSentDate(new Date());
SMTPTransport transport = (SMTPTransport) session.getTransport("smtp");
transport.connect("smtp.live.com", "mail#hotmail.com", pass);
transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
transport.close();
} catch (MessagingException e) {
ret = false;}
When I use this code in local everything works but when I deploy my application on my hosting server appears the follow trace:
DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.live.com", port 587, isSSL false
220 BLU436-SMTP170.smtp.hotmail.com Microsoft ESMTP MAIL Service, Version: 8.0.9200.16384 ready at Thu, 14 Jan 2016 00:04:21 -0800
DEBUG SMTP: connected to host "smtp.live.com", port: 587
EHLO sbi02.namesservers.net
250-BLU436-SMTP170.smtp.hotmail.com Hello [37.187.179.160]
250-TURN
250-SIZE 41943040
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-TLS
250-STARTTLS
250 OK
DEBUG SMTP: Found extension "TURN", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41943040"
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8bitmime", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "TLS", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "OK", arg ""
STARTTLS
220 2.0.0 SMTP server ready
EHLO sbi02.namesservers.net
250-BLU436-SMTP170.smtp.hotmail.com Hello [37.187.179.160]
250-TURN
250-SIZE 41943040
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-AUTH LOGIN PLAIN XOAUTH2
250 OK
DEBUG SMTP: Found extension "TURN", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41943040"
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8bitmime", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2"
DEBUG SMTP: Found extension "OK", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
535 5.0.0 Authentication Failed
I am quite sure that the account credentials are correct but the authentication fails.
Also I have to say that when I try to do this I receive an e-mail of microsoft says there has been a fraudulent attempt to start session but when I execute the code in local I don't receive this e-mail.
I looked at the page account information and the securty & Privacity section, see my recent activity appears challenge security about this try of send e-mail. In this information the device and platform is unknow and the ip is the of my hosting.
There any way to do this?
I've only found a possible solution to my problem. I have enabled two-steps verification in the account. When this option is enabled hotmail gives you the option of creating application passwords. This password is the password that I use in my application instead of the real password of the hotmail account. This solution works for gmail accounts too.

Unable to connect to smtp.gmail.com from JavaMail based module

This has been working for years but since a few weeks, my JavaMail based modules report an error when trying to connect smtp.gmail.com:
The debugging output looks as follows:
DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning
javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
MessagingException javax.mail.MessagingException: Could
not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException:
Certificate signature validation failed
I cannot seem to understand where this problem comes from and any help on how to track this down would be most appreciated.
It seems as if simply replacing the lib/security/cacerts file with a version of the file from the most current jdk would have solved the problem.

Postfix and JavaMail

Tried sending JavaMail with Postfix installed on my Ubuntu pc.
It seems as though the mail is sent but it never arrives.
I just installed Postfix and have no idea how to configure it as an smtp server.
DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false
220 UsProg.com ESMTP Postfix (Ubuntu)
DEBUG SMTP: connected to host "localhost", port: 25
EHLO eitan-pc
250-UsProg.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "10240000"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<avicohen974631#gmail.com>
250 2.1.0 Ok
RCPT TO:<eitan.lp#gmail.com>
250 2.1.5 Ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP: *******#gmail.com
DATA
354 End data with <CR><LF>.<CR><LF>
Date: Sun, 17 May 2015 23:23:26 +0300 (IDT)
From: avicohen974631#gmail.com
To: *********#gmail.com
Message-ID: <2064112929.0.1431894206597.JavaMail.eitan#eitan-pc>
Subject: =?UTF-8?B?16DXmdeh15nXldefINei150g16TXqNeV16fXodeZ?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64
15TXldeT16LXlCDXlteQ16og16DXqdec15fXlCDXk9eo15og16nXqNeqINeQ16DXldeg15nXnteZ
.
250 2.0.0 Ok: queued as 99611E18F1
QUIT
221 2.0.0 Bye
Mail sent to '********#gmail.com' from avicohen974631#gmail.com
Task complete. 1 mails in 0 seconds

Is javax.mail using two smtp sessions for each mail?

So we're debugging some network issues were sending mail takes 5 seconds from telnet to the smptp server. The problem with sending mail with javax.mail is that it takes 10 seconds... We've turned on logging in javax.mail and it looks like it's opening two smtp sessions and the first one doesn't send any data. Could this be because of the 5 second delay? some sort of timeout? or is this how javax.mail works?
Our mail code:
Properties props = new Properties();
props.put("mail.smtp.host", _smtpHost);
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
Message newMessage = new MimeMessage(session);
newMessage.setFrom(new InternetAddress(from));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
newMessage.setSubject(subject);
newMessage.setSentDate(sentDate);
newMessage.setContent(content, contenttype);
Transport transport = session.getTransport(SMTP_MAIL);
transport.connect(_smtpHost, _user, _password);
Transport.send(newMessage);
The debug output:
DEBUG: setDebug: JavaMail version 1.4ea
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 "mail.xxx.xxx", port 25, isSSL false
220 mail.xxx.xxx ESMTP Service (Lotus Domino XXX) ready at Mon, 7 Nov 2011 09:15:00 +0100
DEBUG SMTP: connected to host "mail.xxx.xxx", port: 25
EHLO MYCOMPUTER
250-mail.xxx.xxx Hello MYCOMPUTER ([10.xxx.xxx.xxx]), pleased to meet you
250-HELP
250-VRFY
250-EXPN
250-DSN
250-SIZE 256000000
250-8BITMIME
250 PIPELINING
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "EXPN", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "SIZE", arg "256000000"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
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 "mail.xxx.xxx", port 25, isSSL false
220 mail.xxx.xxx ESMTP Service (Lotus Domino XXX) ready at Mon, 7 Nov 2011 09:15:05 +0100
DEBUG SMTP: connected to host "mail.xxx.xxx", port: 25
EHLO MYCOMPUTER
250-mail.xxx.xxx Hello MYCOMPUTER ([10.xxx.xxx.xxx]), pleased to meet you
250-HELP
250-VRFY
250-EXPN
250-DSN
250-SIZE 256000000
250-8BITMIME
250 PIPELINING
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "EXPN", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "SIZE", arg "256000000"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<tommy#xxx.xxx>
250 tommy#xxx.xxx... Sender OK
RCPT TO:<tommy#xxx.xxx>
250 tommy#xxx.xxx... Recipient OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP: tommy#xxx.xxx
DATA
354 Enter message, end with "." on a line by itself
Date: Mon, 7 Nov 2011 09:14:55 +0100 (CET)
From: tommy#xxx.xxx
To: tommy#xxx.xxx
Message-ID: <145229992.01320653699737.JavaMail.XXX#MYCOMPUTER>
Subject: Test av html-mail
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
sending myself an email...
250 Message accepted for delivery
QUIT
221 xxx.xxx.com SMTP Service closing transmission channel
javax.mail doesn't use any Telnet sessions. It uses POP3 or SMTP sessions.

Categories