seam发送邮件email示例

1.配置邮件支持(components.xml)
    <mail:mail-session debug="true" host="xx.stmp.com" password="passwd" port="25" username="user" />


2.写个模板(resetStaffPwdMail.xhtml)
<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
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());
}
}

你可能感兴趣的:(UI,exception,user,email,seam)