解析用spring发邮件验证失败问题_JSP教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:怎样防止网页的内容被别人采集
ASP实例: 怎么防止网页的内容被别人采集,非法的访问你的网站 % '**************************************** ' 怎么防止网页的内容被别人采集,非法的访问你的网站 '**************************************** dim onlyURL,from '***指定来源网址... onlyURL=

用spring发邮件验证失败问题

[See nested exception: org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException]
按照下述步骤,即可消除此异常信息

属性设置如下:

<!-- 邮件认证实现 -->
<bean id="smtpAuthenticator"
class="yourpackge.service.SmtpAuthenticator">
<constructor-arg value="yourname" ></constructor-arg>
<constructor-arg value="yourpassword" ></constructor-arg>
</bean>
<!-- 邮件 mailSession -->
<bean id="mailSession" class="javax.mail.Session"
factory-method="getInstance">
<constructor-arg>
<props>
<prop key="mail.smtp.auth">true</prop>
<!-- 如果mail服务器是ssl认证,则去掉这里的注释符号
<prop key="mail.smtp.socketFactory.port">465</prop>
<prop key="mail.smtp.socketFactory.class">
javax.net.ssl.SSLSocketFactory
</prop>
<prop key="mail.smtp.socketFactory.fallback">
false
</prop>
-->
</props>
</constructor-arg>
<constructor-arg ref="smtpAuthenticator" />
</bean>

<!--
email发送
-->

<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="yoursmtpserver" />
<property name="port" value="25" />
<property name="session" ref="mailSession" />
</bean>
<!--
email 模板
-->
<bean id="mailMessage"
class="org.springframework.mail.SimpleMailMessage">
<property name="from">
<value><![CDATA[laoyin <youremailaddress>]]></value>
</property>
<property name="subject" value="You've got new Rantz!" />
<property name="text">
<value>
<![CDATA[
Someone's been ranting about you! Log in to RoadRantz.com or
click on the link below to see what they had to say.
http://weather.online.tj.cn/?state=%STATE%&plateNumber=%PLATE%
]]>
</value>
</property>
</bean>

追加一个认证类,实现email的用户认证

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;

public class SmtpAuthenticator extends Authenticator {
private String username;
private String password;

public SmtpAuthenticator(String username, String password) {
super();
this.username = username;
this.password = password;
}

public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
}

使用spring 发送邮件,需要注意,一定要把mail.jar 和 activation.jar 放在classpath中。
spring 只是对javamail进行了包装。
如果你的服务器上已经配置了mailsession , 可以利用JNDI来取得你的mailsession设定。
例如:
<bean id="mailSession"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="mail/Session" />
<property name="resourceRef" value="true" />
</bean>
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="session" ref="mailSession" />
</bean>
 

分享:浅析JSP分页教程
JSP分页教程 html xmlns=1999/xhtml head meta http-equiv=Content-Type content=text/html; charset=gb2312 / title设计家园jsp教程/title % //连接字符串 Class.forName(org.gjt.mm.mysql.Driver); Connection connection=Drive

来源:模板无忧//所属分类:JSP教程/更新时间:2010-05-19
相关JSP教程