国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

解析用spring發郵件驗證失敗問題

2024-09-05 00:17:27
字體:
來源:轉載
供稿:網友
用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>
 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 八宿县| 专栏| 丰镇市| 炎陵县| 峨眉山市| 长岛县| 达日县| 邯郸市| 峨边| 翁牛特旗| 亚东县| 深水埗区| 邹平县| 水富县| 筠连县| 大港区| 平顺县| 晴隆县| 垦利县| 肥乡县| 浦县| 宜阳县| 苍山县| 沙雅县| 叙永县| 元阳县| 措美县| 蒙自县| 刚察县| 文水县| 铁岭市| 兴国县| 新蔡县| 宜春市| 石城县| 锡林浩特市| 于都县| 黔西县| 中阳县| 五莲县| 曲松县|