Why is the customized Meteor accounts verification email not display as HTML?

99封情书 提交于 2019-12-25 09:18:03

问题


Here's my code in 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>';
    };

}

And this is the result:

As you can see, the format is ingnored by Gmail. We can se the HTML tags <h1> and <br>.

Why are they not display as HTML?


回答1:


You used the wrong function. If you use Accounts.emailTemplates.verifyEmail.text, the body will be returned as text and not as HTML. So instead, you should use Accounts.emailTemplates.verifyEmail.html.

For example:

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>';
};

Read more about Accounts.emailTemplates.



来源:https://stackoverflow.com/questions/41493811/why-is-the-customized-meteor-accounts-verification-email-not-display-as-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!