无法找到协议提供程序:smtp

时间:2012-06-14 20:30:59

标签: java spring javamail

春天新手。我抓住了以下异常:

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)

我有一个mail-config.xml,它在我的web.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>

我应该能够匿名登录到指定的邮件服务器,因此不需要用户或密码。

我错过了什么?

2 个答案:

答案 0 :(得分:28)

您的类路径中是否有mail.jaractivation.jar

这些类应该提供smtp-provider。

如果您使用的是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>

答案 1 :(得分:0)

我遇到了同样的问题。我使用mailapi作为工件ID,这导致了问题。 我换了 <artifactId>mailapi</artifactId> <artifactId>mail</artifactId>并且工作正常