java 无法找到协议的提供者:smtp
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11040919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to locate provider for protocol: smtp
提问by Nimchip
New to spring. I'm getting the following exception being caught:
春天的新人。我收到以下异常被捕获:
2012-06-14 16:20:57,719 [http-8080-6] ERROR com.nimchip.lmu.data.service.impl.CoworkerServiceImpl - Error sending mail:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp. Failed messages: javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:400) ~[spring-context-support-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:306) ~[spring-context-support-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296) ~[spring-context-support-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at com.nimchip.lmu.data.service.impl.CoworkerServiceImpl.genUpdateNomination(CoworkerServiceImpl.java:224) ~[lmu-dataaccess-1.0.0.jar:na]
at com.nimchip.lmu.controller.coworkerNom.CoworkerController.genUpdateNomination(CoworkerController.java:312)
I have a mail-config.xml which is registered in my web.xml. Here it is:
我有一个在我的 web.xml 中注册的 mail-config.xml。这里是:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="10.30.137.190"/>
<property name="port" value="25"/>
</bean>
</beans>
I should be able to log anonymously to the mail server specified, so no user or password needed.
我应该能够匿名登录到指定的邮件服务器,因此不需要用户或密码。
What am I missing?
我错过了什么?
回答by Udo Held
Do you have the mail.jar
and activation.jar
in your classpath?
你的类路径中有mail.jar
和activation.jar
吗?
These classes should provide the smtp-provider.
这些类应该提供 smtp-provider。
If you are using maven, simply add this to your pom:
如果您使用的是 maven,只需将其添加到您的 pom 中:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.0.2</version>
</dependency>
回答by Madhu
I had the same problem. I was using mailapi as artifact id and that was causing the issue.
I replaced
<artifactId>mailapi</artifactId>
with
<artifactId>mail</artifactId>
and it worked fine
我有同样的问题。我使用 mailapi 作为工件 ID,这导致了问题。我替换
<artifactId>mailapi</artifactId>
了
<artifactId>mail</artifactId>
并且它工作正常