`
liuwei1981
  • 浏览: 753866 次
  • 性别: Icon_minigender_1
  • 来自: 太原
博客专栏
F8258633-f7e0-30b8-bd3a-a0836a5f4de5
Java编程Step-by...
浏览量:156526
社区版块
存档分类
最新评论

应用spring应用javamail发送邮件

阅读更多

使用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

这个发送的邮箱是我刚刚注册的,在按照网上找到的解决方法的资料,仍没有解决后,把邮箱改为我之前一直使用的邮箱,结果发送邮件就成功了,郁闷,这算什么问题?。。。。cool,有哪位大虾能给个说明么?

分享到:
评论
2 楼 liuwei1981 2008-04-14  
明白了,多谢
1 楼 yidwo 2008-04-01  
很简单的原因,新注册的邮箱功能限制问题.现在的邮件服务运营商都限制了使用smtp协议.
举个例子: 163邮箱要在06年前注册的才可以用SMTP. 验证方法可以用outlook测试..

相关推荐

Global site tag (gtag.js) - Google Analytics