9

I am using the following to send emails which works on localhost but not my server.

// server
Meteor.startup(function () {
    process.env.MAIL_URL="smtp://uername%40gmail.com:password@smtp.gmail.com:465/"; 
});

I get the follow error in my logs(it seems like google is blocking it for some reason, is there a way to stop that?

[162.243.52.235] 534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 l10sm1017845qae.41 - gsmtp
    at SMTPClient._actionAUTHComplete (/opt/meteor/app/programs/server/npm/email/main/node_modules/simplesmtp/lib/client.js:826:23)
    at SMTPClient._onData (/opt/meteor/app/programs/server/npm/email/main/node_modules/simplesmtp/lib/client.js:329:29)
    at CleartextStream.EventEmitter.emit (events.js:95:17)
    at CleartextStream.<anonymous> (_stream_readable.js:746:14)
    at CleartextStream.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at _stream_readable.js:401:7
    at process._tickCallback (node.js:415:13)

This is the event that I think sends initiates the email sending. I know that meteor is now setup to use mailgun, is there a way to modify this to just use mailgun instead of meteor without process.env?

Template.forgotPassword.events({
    'submit #forgotPasswordForm': function(e, t) {
        e.preventDefault();

        var forgotPasswordForm = $(e.currentTarget),
            email = trimInput(forgotPasswordForm.find('#forgotPasswordEmail').val().toLowerCase());

        if (isNotEmpty(email) && isEmail(email)) {
            Accounts.forgotPassword({email: email}, function(err) {
                if (err) {
                    if (err.message === 'User not found [403]') {
                        Session.set('alert', 'This email does not exist.');
                    } else {
                        Session.set('alert', 'We\'re sorry but something went wrong.');
                    }
                } else {
                    Session.set('alert', 'Email Sent. Please check your mailbox to reset your password.');

                }
            });
        }
        return false;
    },

    'click #returnToSignIn': function(e, t) {
        Session.set('showForgotPassword', null);
        return false;
    },
});

Packages already installed

enter image description here

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
Anders Kitson
  • 1,413
  • 6
  • 38
  • 98
  • You should not include clear-text (or uri-encoded) passwords in app code. Better to set an environment variable (more secure). Better still--enable 2-factor authentication (for gmail) and then setup an app password (see https://support.google.com/accounts/answer/185833 ). That way if your app or server is compromised, your gmail account is not and you can revoke app access. – gb96 Mar 24 '15 at 03:53

3 Answers3

9

You need to URL encode your username and password else Meteor confuses the two '@' signs with each other.

You could do this in your JS console (with encodeURIComponent(username)) and usually end up with something like

user%40gmail.com:password@smtp.gmail.com:465

You could use Mailgun in the same way, or Mandrill, or any other smtp provider. It's just the username format causing the issues.

Tarang
  • 75,157
  • 39
  • 215
  • 276
  • Unfortuantely I tried that before and that didnt work, but it is that way now. I still get the error in my logs basically telling me google denied me [162.243.52.235] 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 c2sm1240459qan.18 - gsmtp – Anders Kitson Jun 24 '14 at 16:50
  • Does your password have any of `@`, `:`, `.` in it? – Tarang Jun 24 '14 at 16:53
  • just words and numbers, no special characters. – Anders Kitson Jun 24 '14 at 17:03
  • I've edited Anders' question to not detract from the real problem due to the double @ problem. Is this answer still useful? – Dan Dascalescu Jul 25 '14 at 03:00
9

I encountered a similar problem. The method send email work locally but not on the hosting modulus. For my part this was due to a blocking google security (access to my gmail account from Seattle while I live in France has probably seemed fishy to google). I went through several pages to authorize less strict connections to my gmail account. On this page I saw the blockage. So I allowed the less secure applications and allowed access to my account.

If it helps someone ..

d4v
  • 113
  • 1
  • 4
5

Just use the email package with

meteor add email

Then sending email will work. Mine works with port 587 in my config.

Meteor.startup(function () {
    process.env.MAIL_URL = 'smtp://user%40gmail.com:password@smtp.gmail.com:587';
});
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404