简体   繁体   English

javax.mail.NoSuchProviderException:没有smtps的提供者

[英]javax.mail.NoSuchProviderException: No provider for smtps

I'm trying to set up my Java project to be able to send e-mail (via g-mail, if it matters) and am getting "javax.mail.NoSuchProviderException: No provider for smtps" every time I try to run the following line (which is copy/paste from their example). 我正在尝试设置我的Java项目以便能够发送电子邮件(通过g-mail,如果它很重要)并且每次我尝试运行时都会收到“javax.mail.NoSuchProviderException:没有smtps的提供者”以下行(从他们的例子中复制/粘贴)。

Transport transport = session.getTransport("smtps");

I've looked around and found that this is generally thrown because you don't have the mail.jar included in your classpath, but I do in fact have the mail.jar included. 我环顾四周,发现这通常被抛出,因为你没有在你的类路径中包含mail.jar,但事实上我确实包含了mail.jar。 Since I am running JDK 1.6 I do not need to include the activation.jar according to the FAQ here ( http://www.oracle.com/technetwork/java/javamail/faq-135477.html#classpath ). 由于我运行的是JDK 1.6,因此我不需要根据FAQ( http://www.oracle.com/technetwork/java/javamail/faq-135477.html#classpath )包含activation.jar。 Further, the activation.jar does not seem to be present in version 1.4.7 of javamail. 此外,activation.jar似乎不存在于javamail的1.4.7版本中。

Just in case something got corrupted, I re-downloaded the entire zip from oracle's website, extracted it and added the jar fresh (after deleting the old jar) and I am still getting the same error. 为了防止出现问题,我从oracle的网站上重新下载了整个zip,解压缩并添加了jar(删除旧jar后),我仍然得到同样的错误。 Any thoughts as to what the issue could be at this point? 关于这个问题到底有什么想法吗?

EDIT: Here is the full stack trace that is being printed: 编辑:这是正在打印的完整堆栈跟踪:

javax.mail.NoSuchProviderException: No provider for smtps
    at javax.mail.Session.getProvider(Session.java:433)
    at javax.mail.Session.getTransport(Session.java:627)
    at javax.mail.Session.getTransport(Session.java:608)
... my code that calls getTransport() ...
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
... more of my code ...
    at java.lang.Thread.run(Thread.java:662)

So it turns out that the issue was that an outdated version of mail.jar was included in a project that I was referencing and, upon updating that copy of the mail.jar, the issue was resolved. 事实证明,问题是mail.jar的过时版本包含在我引用的项目中,并且在更新mail.jar的副本时,问题已得到解决。

For future reference, is there any way to log or provide visibility on such jar conflicts? 为了将来参考,有没有办法记录或提供这种jar冲突的可见性?

https://confluence.atlassian.com/confkb/cannot-send-email-due-to-javax-mail-nosuchproviderexception-smtp-error-154079.html https://confluence.atlassian.com/confkb/cannot-send-email-due-to-javax-mail-nosuchproviderexception-smtp-error-154079.html

Just in case anyone makes the same mistake as I have: you have to use lowercase letters for the protocol resolving to work. 万一有人犯了同样的错误: 你必须使用小写字母才能使协议解析起作用。 If you type SMTP as a protocol name instead of smtp you will get the NoSuchProviderException . 如果您键入SMTP作为协议名称而不是smtp您将获得NoSuchProviderException It most likely works the same way for all other providers. 对于所有其他提供商,它很可能以相同的方式工作。

Make sure that you have the javax.mail.jar in you build path. 确保在构建路径中有javax.mail.jar。 If you are using eclipse you may have to refresh or right click your project in the files explorer, select configure build path, add external JAR and then add it to the build path. 如果您正在使用eclipse,则可能必须在文件资源管理器中刷新或右键单击您的项目,选择configure build path,添加外部JAR,然后将其添加到构建路径。 Send email using java gives working code (I've tested it) in case you just want to look over yours. 使用java发送电子邮件给出了工作代码(我已经测试过了),以防你只是想看看你的。 If that is not the problem, or you are not using eclipse, a stack trace would be nice 如果这不是问题,或者你没有使用eclipse,那么堆栈跟踪会很好

When you use Mail API make sure that which protocol are you expecting to work with? 当您使用Mail API时,请确保您希望使用哪种协议? In this case you are missing smtp.jar with your eclipse project. 在这种情况下,你的eclipse项目缺少smtp.jar。

there are several jars for different protocols are available in mail api. 在邮件api中有几个不同协议的罐子。 EX: dsn.jar , gimap.jar , imap.jar ,mailapi.jar ,pop3.jar ,smtp.jar EX:dsn.jar,gimap.jar,imap.jar,mailapi.jar,pop3.jar,smtp.jar

JavaMail asks the ClassLoader for the configuration file that configures the protocol providers. JavaMail向ClassLoader请求配置协议提供程序的配置文件。 If the ClassLoader doesn't work correctly, JavaMail won't be able to find the configuration file. 如果ClassLoader无法正常工作,JavaMail将无法找到配置文件。 There's an incompatibility between the way the OSGi ClassLoaders work and what JavaMail expects, which can cause this problem. OSGi ClassLoader的工作方式与JavaMail期望的方式之间存在不兼容性,这可能导致此问题。 If you're running your application in Eclipse itself, that might explain this problem. 如果您在Eclipse中运行应用程序,则可能会解释此问题。 Another common cause of this problem is importing the mail.jar file into your project in such a way that the class files are extracted from the jar file and included in your application, but the configuration files are left behind. 此问题的另一个常见原因是将mail.jar文件导入到项目中,以便从jar文件中提取类文件并将其包含在应用程序中,但配置文件会被遗忘。

Try running your program from the command line using the "java" command and with the mail.jar file in your CLASSPATH. 尝试使用“java”命令和CLASSPATH中的mail.jar文件从命令行运行程序。

for the benefit of others with a similar problem as I had. 为了其他人的利益,我遇到了类似的问题。

make sure you remember to set 确保你记得设置

 properties.put("mail.transport.protocol", "smtp"));

instead of 代替

 properties.put("mail.transport.protocol", "SMTP"));

I had mail.jar and activation.jar in tomcat's lib directory and mailapi.jar in application's lib directory. 我在tomcat的lib目录中有mail.jar和activation.jar,在应用程序的lib目录中有mailapi.jar。 Application was reading mailapi.jar during runtime, since mailapi.jar is light weight version of mailing api and it needs smtp.jar that why application was throwing smtp exception. 应用程序在运行时读取mailapi.jar,因为mailapi.jar是邮件api的轻量级版本,它需要smtp.jar,为什么应用程序抛出smtp异常。 So, if you want to get rid of this exception, 所以,如果你想摆脱这个例外,

Please resolve conflict between mail.jar and mailapi.jar by: 请解决mail.jar和mailapi.jar之间的冲突:

  • Removing mailapi.jar (if it is there in the classpath). 删除mailapi.jar(如果它在类路径中)。
  • OR just keep one pair of mailapi.jar and smtp.jar in the classpath and remove 或者只是在类路径中保留一对mailapi.jar和smtp.jar并删除
    mail.jar. 的mail.jar。
  • OR just keep one pair of mail.jar and activation.jar in the classpath (clean approach). 或者只在类路径中保留一对mail.jar和activation.jar(干净的方法)。

(FYI: I searched file system to find out mail related jar files and got to know that I have conflicting jar file in the following path (added by gradle in classpath) C:\\workspace.metadata.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\testapp\\WEB-INF\\lib) (仅供参考:我搜索文件系统以找出与邮件相关的jar文件,并且知道我在以下路径中有冲突的jar文件(在类路径中由gradle添加)C:\\ workspace.metadata.plugins \\ org.eclipse.wst。 server.core \\ TMP0 \\ wtpwebapps \\ testapp \\ WEB-INF \\ lib中)

I got the same issue. 我遇到了同样的问题。 i resolved it by adding the correct dependency in maven. 我通过在maven中添加正确的依赖项来解决它。 group id - javax.mail artifactory - mail version 1.4.7 group id - javax.mail artifactory - 邮件版本1.4.7

if you are doing, without maven build, add the correct library for javax.mail 如果您正在做,没有maven构建,请为javax.mail添加正确的库

尝试

Transport transport = session.getTransport("smtp");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javax.mail.NoSuchProviderException:本地没有提供程序 - javax.mail.NoSuchProviderException: No provider for local javax.mail.NoSuchProviderException:没有用于NORMAL的提供程序 - javax.mail.NoSuchProviderException: No provider for NORMAL javax.mail.NoSuchProviderException:$ {mail.protocol}的没有提供者 - javax.mail.NoSuchProviderException: No provider for ${mail.protocol} javax.mail.NoSuchProviderException:smtp - javax.mail.NoSuchProviderException: smtp JavaMail API错误(javax.mail.NoSuchProviderException:无效的提供程序) - JavaMail API Error (javax.mail.NoSuchProviderException: invalid provider) javax.mail.NoSuchProviderException:无效的协议:空 - javax.mail.NoSuchProviderException: Invalid protocol :null javax.mail.NoSuchProviderException:使用Intellij运行spring应用程序时,没有SMTP错误提供程序 - javax.mail.NoSuchProviderException: No provider for SMTP error while running spring application using Intellij 无法发送邮件 - javax.mail.NoSuchProviderException:smtp - Unable to send mail - javax.mail.NoSuchProviderException: smtp 尝试使用java发送邮件时获取javax.mail.NoSuchProviderException - Getting javax.mail.NoSuchProviderException when try to send mail using java 在尝试轮询邮件服务器时获取 javax.mail.NoSuchProviderException:imap - Getting javax.mail.NoSuchProviderException: imap when trying to poll a mail server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM