使用电子邮件模板

在ax中有时会需要发送固定格式的邮件给用户,在ax中有提供邮件模板功能,邮件模板使用了两个表

  1. SysEmailTable
  2. SysEmailMessageTable

SysEmailTable保存的是表头,SysEmialMessageTable保存了邮件模板的内容。

现在我们调用系统SysEmailTable::SendMail()来发送邮件:(有关邮件服务器参数请先在系统设置中设置)

static void SendEmail(Args _args)
{
    Map           map = new Map(Types::String,Types::String);
    SysEmailTable sysEmailTable = SysEmailTable::find("Alerts");
    Session       session= new Session();
    LanguageId    languageId;
    ;
    languageId = session.interfaceLanguage();  //获取当前LanguageID
    map.insert("message","HelloWorld");
    map.insert("for","Macro.Feng");
    map.insert("occurred","AAA");
    map.insert("company","NJ");
    map.insert("event","NJ_event");
    map.insert("data","No Data!!!");
    map.insert("subject","No subject");
    if (!sysEmailTable)
        return;
    sysEmailTable::sendMail(sysEmailTable.EmailId,
                            languageId,
                            "macro.feng@py.nelson-jewellery.com",
                            map);
    return;
}

上述代码中的map 用于指定邮件模板中的参数,在SendMail方法调用了SysEmailMessage::stringExpand()方法将模板中的参数替换成Map键值。

image

posted @ 2012-03-13 11:37  perock  阅读(749)  评论(0编辑  收藏  举报