ali haider
ali haider

Reputation: 20192

issue when using SMTP and javax.mail

I am using the following in my sbt build file (versions are mentioned in the build file):

  "javax.mail" % "javax.mail-api" % "1.5.5",
  "javax.mail" % "mail" % "1.4.7",

I can run the application that runs the following code on one computer but not another. I have tried clearing up the ivy cache and reloading the javax mail packages but that has not helped. Any idea what I might be doing wrong?

final Transport transport = session.getTransport(prop.getProperty("mail.smtp.protocol"));
transport.connect(prop.getProperty("smtp.username"), "");

The properties being used are not null and are being used locally on one computer (and also by another process on the same computer where I am running into issues - that process is no longer running on that computer and should not have an open transport connection).

Exception

java.lang.NoSuchMethodError: com.sun.mail.util.TraceInputStream.<init>(Ljava/io/InputStream;Lcom/sun/mail/util/MailLogger;)V
    at com.sun.mail.smtp.SMTPTransport.initStreams(SMTPTransport.java:2014)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1936)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
    at javax.mail.Service.connect(Service.java:291)
    at javax.mail.Service.connect(Service.java:172)
    at javax.mail.Service.connect(Service.java:192)

com.sun.mail.smtp.SMTPTransport v1.4.7

private void More ...initStreams() throws IOException {
2011    boolean quote = PropUtil.getBooleanSessionProperty(session,
2012                    "mail.debug.quote", false);
2013
2014    traceInput =
2015        new TraceInputStream(serverSocket.getInputStream(), traceLogger);

Any thoughts on how I should go about troubleshooting this? I have tried running the session in debug:

session.setDebug(true);

I do not think its a firewall issue because I can run another process using the same SMTP config (host/port/credentials) and that is able to connect without any exceptions.

Upvotes: 1

Views: 6618

Answers (2)

ali haider
ali haider

Reputation: 20192

The issue was caused by transitive dependency in the build file (whereby another dependency was pulling an older version of javax.mail for the application). Excluding the transitive dependency (using the exclusion rule in sbt) should resolve the issue.

Upvotes: 2

Cristian Meneses
Cristian Meneses

Reputation: 4041

This error is related to a missing smtp.jar on your classpath.

You can download it as part of the JavaMail API here

Upvotes: 1

Related Questions