找不到协议的提供程序:smtp

2022-09-03 18:11:51

春天的新手。我收到以下异常:

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)

我有一个邮件配置.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>

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

我错过了什么?


答案 1

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

这些类应提供 smtp 提供程序。

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

答案 2

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


推荐