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

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.

Related

Custom jre create with jlink can't send mail using jakarta mail api

I am using custom made jre using jlink and when I send mail
this no Error show and suddenly stop custom jre
please see this i got this error three day ago i google it i cant find solutions please developers help me
D:\java\jkl\bin>java --module App/pack.Main
Mar 04, 2022 11:06:19 PM jakarta.mail.Session loadResource
WARNING: expected resource not found: /META-INF/javamail.default.address.map
DEBUG: setDebug: Jakarta Mail version 2.0.1
DEBUG: getProvider() returning jakarta.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.gmail.com, user=visha, password=
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true
D:\java\jkl\bin>
Note: when i use comand
Jlink --module-path D:\java\output --add-modules App --output D:\java\jkl --bind-services
work fine mail send successful but jre size 137mb this is not gud for my project just only one main class or send mail class in my project
Why this happen...

JavaMail - Client was not authenticated to send anonymous mail during MAIL FROM

I'm trying to use JavaMail to send emails through office365 valid account. However, I am receiving the same exception '530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM'. Following the simple code I am using for testing:
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.office365.com");
props.put("mail.smtp.port", "587");
props.put("mail.debug", "true");
Session session = Session.getInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(USER_NAME, USER_PASS);
}
});
try {
final Message message = new MimeMessage(session);
message.setRecipient(Message.RecipientType.TO, new InternetAddress(USER_NAME));
message.setFrom(new InternetAddress(USER_NAME));
message.setSubject(subject);
message.setText(messageContent);
message.setSentDate(new Date());
Transport.send(message);
System.out.println("Send OK");
} catch (final MessagingException ex) {
System.out.println(ex.getMessage());
}
Following the debug output:
DEBUG: JavaMail version 1.3
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jre1.8.0_171\lib\javamail.providers (The system cannot find the file specified)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jre1.8.0_171\lib\javamail.address.map (The system cannot find the file specified)
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG: SMTPTransport trying to connect to host "smtp.office365.com", port 587
DEBUG SMTP RCVD: 220 xxxxx.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 6 Jun 2019 07:53:32 +0000
DEBUG: SMTPTransport connected to host "smtp.office365.com", port: 587
DEBUG SMTP SENT: EHLO L3343005201
DEBUG SMTP RCVD: 250-xxxxx.outlook.office365.com Hello [92.242.173.14]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP Found extension "SIZE", arg "157286400"
DEBUG SMTP Found extension "PIPELINING", arg ""
DEBUG SMTP Found extension "DSN", arg ""
DEBUG SMTP Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP Found extension "STARTTLS", arg ""
DEBUG SMTP Found extension "8BITMIME", arg ""
DEBUG SMTP Found extension "BINARYMIME", arg ""
DEBUG SMTP Found extension "CHUNKING", arg ""
DEBUG SMTP Found extension "SMTPUTF8", arg ""
DEBUG SMTP: use8bit false
DEBUG SMTP SENT: MAIL FROM:<sender#domain>
DEBUG SMTP RCVD: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [xxxxx.yyyyy.outlook.com]
DEBUG SMTP SENT: QUIT
Sending failed;
nested exception is:
class javax.mail.MessagingException: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [xxxxx.yyyyy]
From logs it seems the authentication is not working, and the connection port goes to 25 rather than the 587 as specified in the properties.
I tried adding other properties as well, like
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.user", USER_NAME);
props.put("mail.smtp.password", USER_PASS);
props.put("mail.smtp.from", USER_NAME);
in any combination, but no results.
I've also tried to use the updated version of the JavaMail library, but the exception is the same. Am I missing any configuration on the mail account? Or from code?
Thanks in advance
Edited: changing the port from 587 (int) to "587" (string) solved the port issue in the debug port, but the same Client authentication error occurs
JavaMail 1.3 is 17 years old! Where did you find it? Switch to the current release and then fix all these common JavaMail mistakes.

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

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.

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

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