以下转自csdn上的一个回答,留着用的时候参考,防止到时找不到
1.配置邮件支持(components.xml)
Xml代码
<SPAN style="FONT-SIZE: small"><mail:mail-session debug="true" host="xx.stmp.com" password="passwd" port="25" username="user" /> </SPAN>
<mail:mail-session debug="true" host="xx.stmp.com" password="passwd" port="25" username="user" />
2.写个模板(resetStaffPwdMail.xhtml)
Xml代码
<m:message charset="UTF-8"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:m="http://jboss.com/products/seam/mail"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<m:from name="系统管理员" address="
[email protected]" />
<m:to name="#{staffPasswordMgr.staffName}">#{staffPasswordMgr.staffEmail} </m:to>
<m:subject>用户密码重置通知! </m:subject>
<m:body>
<p> <h:outputText value="亲爱的[#{staffPasswordMgr.staffName}" />]: </p>
<p>您的用户密码已经被[ <h:outputText value="#{staff.loginName}" />]成功重置! </p>
<p>登陆用户帐号: <h:outputText value="#{staffPasswordMgr.staffId}" /> </p>
<p>登陆用户密码: <h:outputText value="#{staffPasswordMgr.staffPwd}" /> </p>
<p>该邮件由系统自动发出,不必回复,有不明之处,请和系统管理员联系! </p>
</m:body>
</m:message>
<m:message charset="UTF-8" xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:m="http://jboss.com/products/seam/mail" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <m:from name="系统管理员" address="
[email protected]" /> <m:to name="#{staffPasswordMgr.staffName}">#{staffPasswordMgr.staffEmail} </m:to> <m:subject>用户密码重置通知! </m:subject> <m:body> <p> <h:outputText value="亲爱的[#{staffPasswordMgr.staffName}" />]: </p> <p>您的用户密码已经被[ <h:outputText value="#{staff.loginName}" />]成功重置! </p> <p>登陆用户帐号: <h:outputText value="#{staffPasswordMgr.staffId}" /> </p> <p>登陆用户密码: <h:outputText value="#{staffPasswordMgr.staffPwd}" /> </p> <p>该邮件由系统自动发出,不必回复,有不明之处,请和系统管理员联系! </p> </m:body> </m:message>
3.action
Java代码
public void sendMail() throws Exception {
try {
renderer.render("/admin/staff/resetStaffPwdMail.xhtml");
facesMessages.add("邮件发送成功!");
} catch (Exception e) {
log.error("邮件发送失败:", e.toString());
facesMessages.add("邮件发送失败:" + e.toString());
}
}