Loupax
Loupax

Reputation: 4914

How can I send emails using my own mail server in Meteor?

I am trying to enable email support for my Meteor application, and since I have my own server I want to also use my own mail server. So I installed postfix in my Debian wheezy server and successfully sent and email to my GMail address, so that means the mail server works properly and sends emails.

When I deploy my Meteor app and try to send an email though, say to do a password reset, my app crashes with the following error:

Exception while invoking method 'forgotPassword' RecipientError: Can't send mail - all recipients were rejected
at Object.Future.wait (/home/loupax/phial/bundle/programs/server/node_modules/fibers/future.js:326:15)
at smtpSend (packages/email/email.js:94)
at Object.Email.send (packages/email/email.js:155)
...
...

My MAIL_URL environment variable is in the format MAIL_URL=smtp://my_domain.tld.

Upvotes: 9

Views: 4636

Answers (3)

Devang Hire
Devang Hire

Reputation: 314

for forgot password email, follow below steps

1) create smtp.js file in server folder and past below code in it

 Meteor.startup(function () {
   process.env.MAIL_URL = 
   'smtps://[email protected]:[email protected]:465';
 });

2) paste below code in forgot password.js file

   Template.forgot.events({

'click #forgot'(event,template) {
    event.preventDefault();

    let email = $("#email").val();

    // paste below code in server.main.js -> in Meteor.startup function.

    /* Accounts.urls.resetPassword = function(token) {
        return Meteor.absoluteUrl('reset-password/' + token);
    };*/

    Accounts.forgotPassword({email:email},function (error,result) {

        if(error)
        {
            alert(error);
        }
        else
        {
            console.log(result);
            alert("mail sent ..!! Check your mail box");
           FlowRouter.go('/login');
         }
      });
   }

 });

3 ) in main.js file in server folder paste below code import '../server/smtp';

Meteor.startup(() => {
  // code to run on server at startup
    Accounts.urls.resetPassword = function(token) {
        return Meteor.absoluteUrl('reset-password/' + token);
    };
});

check your mail

Upvotes: 0

Loupax
Loupax

Reputation: 4914

Looks like all I had to do, is change the MAIL_URL environmental variable from smtp://my_domain.tld to smtp://localhost. After that everything worked just fine

Upvotes: 4

Tarang
Tarang

Reputation: 75945

Is your server on Amazon? Sometimes SMTP servers are known to block anything sent from certain hosting providers entire IP ranges to block spam.

You might want to consider using a different SMTP server, Amazon's SES, or Mandrill (which has a meteorite package to help) (personally I use both SES and Mandrill).

Note its not only Amazons IP blocks which are in this, its also any hosting provider a spammer can quickly set up. Your SMTP sever probably employs a list from somewhere with all these ips on it

Upvotes: 0

Related Questions