How come my Meteor app with accounts package is not sending a verification email?
Asked Answered
S

2

12

I am making a meteor app and I have the mrt accounts-password package added as well as mrt accounts-ui-bootstrap-dropdown.

I have added the loginbuttons so users can create an account and that works just fine. I am using all defaults.

On the server I have the code:

Accounts.config({
  sendVerificationEmail: true,
  forbidClientAccountCreation: false
});

And when I create a new account, the server console prints:

I20130821-18:31:42.105(-4)? ====== BEGIN MAIL #0 ======
I20130821-18:31:42.106(-4)? MIME-Version: 1.0
I20130821-18:31:42.107(-4)? From: "Meteor Accounts" <[email protected]>
I20130821-18:31:42.108(-4)? To: [email protected]
I20130821-18:31:42.108(-4)? Subject: How to verify email address on localhost:3000
I20130821-18:31:42.109(-4)? Content-Type: text/plain; charset=utf-8
I20130821-18:31:42.109(-4)? Content-Transfer-Encoding: quoted-printable
I20130821-18:31:42.109(-4)? Hello,
I20130821-18:31:42.110(-4)? To verify your account email, simply click the link below.
I20130821-18:31:42.110(-4)? http://localhost:3000/#/verify-email/C2vJeaDLeMkkWmcRY
I20130821-18:31:42.111(-4)? Thanks.
I20130821-18:31:42.111(-4)? ====== END MAIL #0 ======

So it looks like it sends the email from the server but I never get the verification email in my inbox. And I tried multiple times and it has been over an hour! I also checked my spam folder. What gives?

Thanks in advance

Slapjack answered 21/8, 2013 at 22:40 Comment(0)
C
18

See here: http://docs.meteor.com/#email

If MAIL_URL is not set (eg, when running your application locally), Email.send outputs the message to standard output instead

Web servers such as Meteor cannot send emails by themselves, they need a SMTP server to do that. You need to set up one and set it with MAIL_URL variable.

Crew answered 21/8, 2013 at 23:5 Comment(7)
Ah I see, so do I add 'var MAIL_URL = smtp://USERNAME:PASSWORD@HOST:PORT/' to the the environment file? I've never added to the env file, how do I do this?Slapjack
No, you set it up as an environment variable. Alternatively, you could set it with process.env.MAIL_URL = ..., but this is a hacky method.Crew
Ah so to set it up as an environment variable I just type 'export MAIL_URL = smtp://USERNAME:PASSWORD@HOST:PORT/' into terminal? This will add it to my local machine environment, but if I deploy to Heroku, is there a way to include a special .env file in the actual meteor project that is only readable by Heroku server?Slapjack
There's a command for that: heroku config:set MAIL_URL=.... You'll also need to set up ROOT_URL and most probably BUILDPACK_URL the same way.Crew
btw for others trying to get this to work, you need to add 'export MAIL_URL = smtp://USERNAME:PASSWORD@HOST:PORT/' replacing the smtp info with your own, into the .bash_profile, a special file on your computer that has all the environment variables. Then log out and log back in to update variables and then it should work.Slapjack
Or, you can run your app with command MAIL_URL=... meteor - especially handy if you have several apps.Crew
ah that is quite handySlapjack
G
14

To configure the MAIL_URL, don't forget to add the core email package:

meteor add email

And then, server-side:

// server/smtp.js
Meteor.startup(function () {
  smtp = {
    username: 'your_username',   // eg: [email protected]
    password: 'your_password',   // eg: 3eeP1gtizk5eziohfervU
    server:   'smtp.gmail.com',  // eg: mail.gandi.net
    port: 25
  }

  process.env.MAIL_URL = 'smtp://' + encodeURIComponent(smtp.username) + ':' + encodeURIComponent(smtp.password) + '@' + encodeURIComponent(smtp.server) + ':' + smtp.port;
});

Read More: Verify an Email with Meteor Accounts.

Girl answered 25/8, 2014 at 13:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.