为什么定制的Meteor帐户验证电子邮件不会显示为HTML?

时间:2017-01-05 20:10:00

标签: javascript meteor sendmail meteor-accounts email-verification

这是 imports/api/friends/methods.js

中的代码
import {Meteor} from "meteor/meteor";
import {Accounts} from "meteor/accounts-base";

if (Meteor.isServer) {

    Accounts.emailTemplates.siteName = "....";
    Accounts.emailTemplates.from = "example01  <example01@gmail.com>";
    Accounts.emailTemplates.verifyEmail.from  = function () {
        return "example01  <example01@gmail.com>";
    };
    Accounts.emailTemplates.verifyEmail.text = function(user, url) {
        return '<h1>Thank you for your registration.</h1><br/><a href="' + url + '">Verify eMail</a>';
    };

}

这就是结果:

Customized Meteor accounts verification email does not display HTML

正如您所看到的,这种格式已被Gmail所淹没。我们可以查看HTML标记<h1><br>

为什么它们不显示为HTML?

1 个答案:

答案 0 :(得分:3)

您使用了错误的功能。如果您使用Accounts.emailTemplates.verifyEmail.text,正文将以文本形式返回,而不是HTML。因此,您应该使用Accounts.emailTemplates.verifyEmail.html

例如:

Accounts.emailTemplates.verifyEmail.html = function(user, url) {
    /* Return your HTML code here: */
    return '<h1>Thank you for your registration.</h1><br/><a href="' + url + '">Verify eMail</a>';
};

详细了解 Accounts.emailTemplates