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

218 views Asked by At

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  <[email protected]>";
    Accounts.emailTemplates.verifyEmail.from  = function () {
        return "example01  <[email protected]>";
    };
    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:

Customized Meteor accounts verification email does not display HTML

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

There are 1 answers

0
Matthias A. Eckhart On

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.