Slow sendmail (javamail) performance with different mail api banks

I am testing a sendmail example as stated in https://javaee.imtqy.com/javamail/FAQ . This is a simple operation to send mail without SSL and without attachments. It works great everywhere, but on the client we have performance downgrade when the mail api gets newer.

The server is windows, java 1.8.131, they use the same mail servers and mail accounts, as well as the address and source of java in all test cases. The only difference is the use of mailapi. I run the program with

java -cp javax.mail.1.XXjar; sendmailtesttool.jar SendMail

I tried 100 times for each api mail and got the average duration.

  • JavaMailApi Version: Duration 1.4.0 <1 sec.
  • JavaMailApi version: 1.4.2 duration 9-10 seconds.
  • JavaMailApi version: duration 1.5.2 29-30 sec.
  • JavaMailApi version: 1.5.6 duration 29-30 sec.
  • JavaMailApi version: duration 1.6.0 29-30 sec.

Source used:

Properties properties = new Properties();
properties.put("mail.smtp.host", 192.168.0.X); // use default port25
Session session = Session.getInstance(properties);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(..);
msg.setSubject(..);
msg.setRecipients(..);
//no attachments
MultiPart mp = new MultiPart();
MimeBodyPart bp = new MimeBodyPart();
DataSource ds = ByteArrayDataSource("foo"..);
DataHandler dh = new DataHandler(ds);
bp.setDataHandler(dh);
mp.addBodyPart(bp);
msg.setContent(mp);

Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
msg.saveChanges(); // is really needed ? (no reply/forward)
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();

I added test tool outputs:

Java Mail Api 1.4.0

    Sending mail.....start

    Setting port to:25

    Setting host to:192.168.0.213

    Set additional session prop host to prevent HELO

    Set additional session prop from to prevent EHLO

    Session generated with authenticator took:63

    Message generated took:47

    Parse from address took:0

    Set from address to message took:0

    Set recipients took:0

    Get all recipients took:0

    Set cc, bcc took:0

    Parse subject took:16

    Set subject to message took:0

    Set body text took:0

    Set content took:0

    Set sent date took:15

    Transport generated took:32

    Connected to transport took:93

    Save changes took:0

    Message send took:94

    Transport closed took:0

    Message id fetched took:0

Sending mail ..... completed in 391

Average value: 391.0

Java Mail Api 1.5.6

    Sending mail.....start

    Setting port to:25

    Setting host to:192.168.0.213

    Set additional session prop host to prevent HELO

    Set additional session prop from to prevent EHLO

    Session generated with authenticator took:62

    Message generated took:63

    Parse from address took:0

    Set from address to message took:16

    Set recipients took:0

    Get all recipients took:0

    Set cc, bcc took:0

    Parse subject took:0

    Set subject to message took:0

    Set body text took:0

    Set content took:0

    Set sent date took:15

    Transport generated took:32

    Connected to transport took:9126

    Save changes took:0

    Message send took:47

    Transport closed took:0

    Message id fetched took:0

Sending mail ..... completed in 9423

Average value: 9423.0

Jvm mail debugging outputs

Java Mail API 1.4.0

DEBUG: setDebug: JavaMail version 1.4ea

DEBUG: getProvider () returns javax.mail.Provider [TRANSPORT, SMTP, com.sun.mail.s

mtp.SMTPTransport, Sun Microsystems, Inc]

DEBUG SMTP: useEhlo true, useAuth true

DEBUG SMTP: attempt to connect to host "192.168.0.X", port 25, isSSL false

220 mail. ******. com ESMTP Postfix

DEBUG SMTP: "192.168.0.X", : 25

EHLO WIN-0RL58R42TTN

250 . ******.

250-PIPELINING

250-SIZE 102400000

250-VRFY

250-ETRN

250-STARTTLS

250-AUTH PLAIN LOGIN

250-AUTH = PLAIN LOGIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

DEBUG SMTP: "PIPELINING", arg "

DEBUG SMTP: " SIZE ", arg" 102400000 "

DEBUG SMTP: " VRFY", arg "

DEBUG SMTP: " ETRN", arg "

DEBUG SMTP: " STARTTLS", arg "

DEBUG SMTP: " AUTH ", arg" PLAIN LOGIN "

DEBUG SMTP: " AUTH = PLAIN ", arg" LOGIN "

DEBUG SMTP: " ENHANCEDSTATUSCODES", arg "

DEBUG SMTP: " 8BITMIME", arg "

DEBUG SMTP: " DSN ", arg" "

DEBUG SMTP:

334 VXNlcm5hbWU6

am9iaW4uZWxhbmppY2thbEBhbGNvbmVsZWN0cm9uaWNzLmNvbQ ==

334 UGFzc3dvcmQ6

Sk9CSU5ANzc3TnM =

235 2.7.0

DEBUG SMTP: use8bit false

:

250 2.1.0 Ok

RCPT TO:

250 2.1.5 Ok

DEBUG SMTP:

DEBUG SMTP: @******. com

DATA

354 .

: , 14 2017 14:17:46 +0530 (IST)

: sender @******. com

To: receiver @******. com

: < 396180261.01513241266298.JavaMail.sender @******

.com >

: test3

MIME-Version: 1.0

Content-Type: multipart/mixed;

    boundary="----=_Part_0_2093176254.1513241266126"

------ = _ Part_0_2093176254.1513241266126

Content-Type: text/plain; = UTF-8

Content-Transfer-Encoding: 7bit

------ = _ Part_0_2093176254.1513241266126 -

.

250 2.0.0 : 7E38D48F0411

QUIT

221 2.0.0 Bye

Java Mail API 1.5.6

DEBUG: setDebug: JavaMail 1.5.6

DEBUG: getProvider() javax.mail.Provider [, SMTP, com.sun.mail.s

mtp.SMTPTransport, Oracle]

DEBUG SMTP: useEhlo true, useAuth true

DEBUG SMTP: "192.168.0.X", 25, isSSL

220 mail. ******. com ESMTP Postfix

DEBUG SMTP: "192.168.0.X", : 25

EHLO WIN-0RL58R42TTN

250 . ******.

250-PIPELINING

250-SIZE 102400000

250-VRFY

250-ETRN

250-STARTTLS

250-AUTH PLAIN LOGIN

250-AUTH = PLAIN LOGIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

DEBUG SMTP: "PIPELINING", arg "

DEBUG SMTP: " SIZE ", arg" 102400000 "

DEBUG SMTP: " VRFY", arg "

DEBUG SMTP: " ETRN", arg "

DEBUG SMTP: " STARTTLS", arg "

DEBUG SMTP: " AUTH ", arg" PLAIN LOGIN "

DEBUG SMTP: " AUTH = PLAIN ", arg" LOGIN "

DEBUG SMTP: " ENHANCEDSTATUSCODES", arg "

DEBUG SMTP: " 8BITMIME", arg "

DEBUG SMTP: " DSN ", arg" "

DEBUG SMTP: , = 192.168.0.X, user = sender @alc

onelectronics.com, =

DEBUG SMTP: : LOGIN PLAIN DIGEST-MD5 NTL

M XOAUTH2

DEBUG SMTP: LOGIN

DEBUG SMTP: AUTH LOGIN

DEBUG SMTP: AUTH LOGIN

DEBUG SMTP: use8bit false

:

250 2.1.0 Ok

RCPT TO:

250 2.1.5 Ok

DEBUG SMTP:

DEBUG SMTP: @******. com

DATA

354 .

: , 14 . 2017 14:18:03 +0530 (IST)

: sender @******. com

To: receiver @******. com

: < 1109371569.1.1513241292669 @******. com >

: test3

MIME-Version: 1.0

Content-Type: multipart/mixed;

    boundary="----=_Part_0_1349393271.1513241283434"

------ = _ Part_0_1349393271.1513241283434

Content-Type: text/plain; = UTF-8

Content-Transfer-Encoding: 7bit

------ = _ Part_0_1349393271.1513241283434 -

.

250 2.0.0 : D894D48F0411

DEBUG SMTP:

QUIT

221 2.0.0 Bye

+4
2

, . , .

1.6 api.

InetAddress.getCanonicalHostName, InternetAddress.getLocalAddress. InetAddress.getCanonicalHostName . System false , InetAddress.getHostName. - true.

, false, .

java mail apis, - .

+3

. session.getTransport, session.getInstance; , transport.connect(host,..); connect (user, password) , DNS.

+1

Source: https://habr.com/ru/post/1690760/


All Articles