Tweak domain name of links in verification emails


#1

I’m using the Accounts.sendVerificationEmail method.

It would be good if I could customize the domain name of the verification URL that is sent to users on sign-up…

The verification URL’s that are sent through the app in my local development machine look like the following:

http://localhost:3000/#/verify-email/OWnRawy8O_w7n3qj8nDKsIPFirx8u9qVQPWtmKQZGRu

I’m looking for a way to substitute the localhost:3000 string with a domain name so as to have URL’s that look like the following:

http://mydomainname.com/#/verify-email/OWnRawy8O_w7n3qj8nDKsIPFirx8u9qVQPWtmKQZGRu

How can I customize these verification URL’s?


#2

Hi, I do something like this. The first part sets the transport service. The 2nd part sets the from and sitename:

// Configure default email MAIL_URL for accounts
Meteor.startup(function () {

  process.env.MAIL_URL = 'smtp://' +
    encodeURIComponent(Meteor.settings.email.user) + ':' +
    encodeURIComponent(Meteor.settings.email.pass) + '@' +
    encodeURIComponent(Meteor.settings.email.host) + ':' +
    Meteor.settings.email.port;

  Accounts.emailTemplates.siteName = Meteor.settings.public.siteName;
  Accounts.emailTemplates.from = Meteor.settings.public.emailFrom;
});

#3

@michaelcole thanks for your reply :smile:

I would have thought that setting Accounts.emailTemplates.siteName = ‘mydomainname.com would generate the desired URL’s…

http://mydomainname.com/#/verify-email/OWnRawy8O_w7n3qj8nDKsIPFirx8u9qVQPWtmKQZGRu

I have tested the Accounts.emailTemplates.siteName settings with 2 disjoint SMTP servers to no avail.

Am I missing something?


#4

So I use this to set the verify email. Meteor passes URL to these functions when creating the email to send.

// Welcome and Email Verification

Accounts.emailTemplates.verifyEmail.subject = function(user) {
  return 'Welcome to totallyCoolzor.io :-)';
};
Accounts.emailTemplates.verifyEmail.html = function (user, url) {
  return Handlebars.templates.verifyEmail_html({
    emailAddress: user.email(),
    url: url,
  });
};
Accounts.emailTemplates.verifyEmail.text = function (user, url) {
  return Handlebars.templates.verifyEmail_text({
    emailAddress: user.email(),
    url: url,
  });
};

#5

Maybe I’m not being so clear. Sorry about that!

Take for instance this snippet:

Accounts.emailTemplates.verifyEmail.text = function (user, url) {
  return Handlebars.templates.verifyEmail_text({
    emailAddress: user.email(),
    url: url,
  });
};

As far as I understand it,
in said snippet,
the value of url could be something like the following:

http://localhost:3000/#/verify-email/OWnRawy8O_w7n3qj8nDKsIPFirx8u9qVQPWtmKQZGRu

How can I tell Meteor to substitute localhost:3000 with mydomain.com in this string?


#6

Hey there, no problem. You’ll want to set the ROOT_URL environment variable for that. It will vary depending on how you run the server, but something like this should work:

export ROOT_URL=https://mydomain.com
meteor run --port 3012 --settings settings.json

This is assuming that mydomain.com points to the ip of a server with an nginx proxy from port 80->3012