GNU JavaMail: No provider for address: rfc822

2019-03-02 07:29发布

Using OpenJDK 1.7.0 and GNU JavaMail 1.1.2.

During the actual message send call:

SMTPTransport.send(msg);

This happens:

javax.mail.NoSuchProviderException: No provider for address: rfc822
    at javax.mail.Session.getTransport(Session.java:641)
    at javax.mail.Transport.doSend(Transport.java:149)
    at javax.mail.Transport.send(Transport.java:75)

Transport.send(msg) produces the same result.

I'm pretty sure my classpath is OK. Here's how it's defined in build.xml in the JAR task:

<zipfileset src="${sys}/inetlib.jar" includes="**/*.java **/*.class"/>
<zipfileset src="${sys}/gnumail-providers.jar" includes="**/*.java **/*.class"/>
<zipfileset src="${sys}/gnumail.jar" includes="**/*.java **/*.class"/>

Where ${sys} is /usr/share/java. Am I going to have to suck it up and use the Oracle JavaMail API?

2条回答
可以哭但决不认输i
2楼-- · 2019-03-02 08:21

I got the same problem as you and it happened to be caused by the jar geronimo-javamail_1.4_spec messing things up. A simple solution is to exclude it from your dependencies. With Maven, assuming it's a dependency from CXF:

<dependency>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-rt-core</artifactId>
  <version>2.7.5</version>
  <exclusions>
    <exclusion>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-javamail_1.4_spec</artifactId>
  </exclusion>
  </exclusions>
</dependency>

As to know exactly why, I did not took the time to investigate further. It's a multi-thread safety bug for sure (I got it when multiple threads where speaking SMTP at the same time).

Original reference of the solution here.

查看更多
Explosion°爆炸
3楼-- · 2019-03-02 08:25

It looks like your program is trying to set rfc822 as the domain address to be used for the transport layer. Is this a valid address? I suggest searching your code for this reference as the problem is undoubtedly around that area.

查看更多
登录 后发表回答