简体   繁体   中英

SMTP server giving error. Mails not being sent in Meteor App

I am following the Meteor in Action book and there is a simple app that I am making which requires for the SMTP server to be working to send out email verifications on signup.

I followed all the steps but something does not seem right. The user is being created but verification mail is not being sent and in fact, an error is being thrown:

I20150128-16:16:53.221(5.5)? Exception in setTimeout callback: Error: connect ETIMEDOUT
I20150128-16:16:53.225(5.5)?     at Object.Future.wait (/Users/niranjan/.meteor/packages/meteor-tool/.1.0.40.i0mc94++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:326:15)
I20150128-16:16:53.225(5.5)?     at smtpSend (packages/email/email.js:91:1)
I20150128-16:16:53.226(5.5)?     at Object.Email.send (packages/email/email.js:168:1)
I20150128-16:16:53.226(5.5)?     at Object.Accounts.sendVerificationEmail (packages/accounts-password/password_server.js:602:1)
I20150128-16:16:53.226(5.5)?     at app/server/server.js:10:16
I20150128-16:16:53.227(5.5)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150128-16:16:53.227(5.5)?     at packages/meteor/timers.js:6:1
I20150128-16:16:53.227(5.5)?     at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108:1)
I20150128-16:16:53.227(5.5)?     - - - - -
I20150128-16:16:53.227(5.5)?     at errnoException (net.js:904:11)
I20150128-16:16:53.228(5.5)?     at Object.afterConnect [as oncomplete] (net.js:895:19)

I have been trying to debug this but just can't seem to figure out what is happening.

The following is the relevant code - client/templates.html :

  Accounts.onCreateUser(function (options, user) {
      if (options.profile) {
        user.profile = options.profile;
      } else {
        user.profile = "White belt";
      }
      user.profile.rank = "White belt";
      if(options.email) {
        Meteor.setTimeout(function () {
          Accounts.sendVerificationEmail(user._id);  // I think this is the error source
        }, 2 * 1000 );
      }
      return user;
    });

server/smtp.js :

Meteor.startup(function () {
  smtp = {
    username: 'myemail@gmail.com',
    password: 'mysecretpassword',
    servre: 'smtp.gmail.com',
    port: 587
  };
  process.env.MAIL_URL = 'smtp://' + 
      encodeURIComponent(smtp.username) + ':' + 
      encodeURIComponent(smtp.password) + '@' +
      encodeURIComponent(smtp.server) + ':' +
      smtp.port;
});

Accounts.emailTemplates.siteName = "Meteor in Action userApp";
Accounts.emailTemplates.from = "Name <myemail@gmail.com>";

Accounts.emailTemplates.verifyEmail.subject = function (user) {
  return 'Confirm your email address, ' + user.username;
};

Accounts.emailTemplates.verifyEmail.text = function (user, url) {
  return 'Welcome to the Meteor in Action userApp! \n'
    + 'To veryify - \n' + url;
};

Accounts.emailTemplates.verifyEmail.html = function (user, url) {
  return "<h1>Welcome to the Meteor in Action userApp! </h1>"
    + "<p>To verify - </p>" + url;
};

The problem, my friend, lies in the server/smtp.js file where you have misspelled the world server. So the smtp object doesn't have any property called server . You defined as servre .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM