使用spring2.X,来实现javaMail发送邮件,手头上正好有一本《精通spring2.x企业应用开发详解》,按照书上的例子,很快配好了例子和测试demo,
spring的配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.163.com"/>
<property name="username" value="*******"/>
<property name="password" value="*******"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.timeout">25000</prop>
</props>
</property>
</bean>
<bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage">
<property name="from" value="******@163.com"/>
<property name="replyTo" value="******@163.com"/>
<property name="cc" value="*********@163.com"/>
</bean>
<bean id="mailService" class="com.service.mail.MailService">
<property name="mailSender" ref="mailSender"/>
<property name="mailMessage" ref="mailMessage"/>
</bean>
</beans>
但是在实际测试的时候,发送邮件总是报出异常错误:org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException
这个发送的邮箱是我刚刚注册的,在按照网上找到的解决方法的资料,仍没有解决后,把邮箱改为我之前一直使用的邮箱,结果发送邮件就成功了,郁闷,这算什么问题?。。。。,有哪位大虾能给个说明么?