User Accounts with Mailgun for passwd reset and verification

I’m working on a project that has implemented user accounts. I am looking for guidance on using mailgun / 3rd party lib for password reset and verification.

I already have mailgun configured.

In my accounts configuration I have:
confirmPassword: true, enablePasswordChange: true, sendVerificationEmail: true, showAddRemoveServices: false, showForgotPasswordLink: true, showResendVerificationEmailLink: false,

But I’m stuck on what to do next.

So I have kind of the same problem.
I am also using meteor-useraccounts successfully but I can’t get the forgot password function to work.
It seems to me that behind the scenes, all this package is doing, is calling Accounts.forgotPassword().
Which of course makes sense.
For all my “normal emails” in my code I am using the standard mailgun npm package. This works perfectly fine. but obviously I can’t use it here. So I tried setting my MAIL_URL environment variable like so:

export MAIL_URL="smtp://postmaster@<mysandboxid>.mailgun.org:<default-sandbox-password>@smtp.mailgun.org:587"

When I change something in that environment variable I immediately get an error when I try to reset password like Exception while invoking method 'forgotPassword' { stack: 'AuthError: Invalid login - 535 5.7.0 Mailgun is not loving your login or password' }. So my login seems to be correct. but NO EMAIL is sent, I also can’t see any mail in the logs of mailgun.

Can anyone help?!

If I had to guess, I’m saying that you aren’t encoding your url? For example, in your username, the @ should be %40.

Just tried it. Did not change anything! :frowning:
Again no errors in the console but also no mail, also in the mailgun logs.

Here’s how I use MailGun :

server side code

dependency

settings.json

@warehouseman
Sorry only saw your reply just now!
Til now I am using this package: mailgun-js.

I was not aware of the implementation your are using in your “server side code”?!
How does this hook into Meteor’s native “resetPassword” functionality and run this code instead of the “standard one”?

@klabauter

If I recall correctly, I wanted to use a generic mailer rather than a mailgun specific one, or a Meteor specific one.

I’m very interested in working with enduring tools. With over 40 different nodemailer transports available, and 30k daily downloads of nodemailer, I figure I won’t soon have to worry about finding a well supported mailer package.

@warehouseman
Ok thanks that makes total sense! :slight_smile: just one more thing as I already asked: can you explain why this is working? I do not really understand how your mailer.resetPassword = function resetPassword(_email, _id, _validator) { ... } function somehow “overwrites” Meteor’s standard resetPassword() function?!

is there any reason why you’re not using the standard Email package? I use Mailgun too but just use that and it works perfectly.

@warehouseman uses meteor’s method to handle the reset password :wink:

1 Like

@cstrat
As stated above I never got the standard MAIL_URL env var approach to work. Never got any errors but also my emails were never sent. They don’t even show up in the mailgun dashboard logs. :frowning:
The only way I got emails to work was using the mailgun.js package.

Can you maybe elaborate how you got mailgun to work with the standard Email package? :slight_smile:

@rlespagnol
Ahh now I get what you guys mean! @warehouseman is completely ignoring Meteor’s default resetpassword functionality and wrote his own method handling that plus sending the mail. That makes sense!

Maybe it would also work to do something like this:

import { Accounts } from 'meteor/accounts-base'

Accounts.sendResetPasswordEmail = function(userId, email) {
    // my custom send mail stuff here
}

… so basically overwriting the default Accounts.sendResetPasswordEmail function.
This should work right?
Any idea where I would have to put this piece of code? somewhere in /imports/startup/server maybe?

I deploy my app to nodechef, in the deploy process I need to set the environment variables. So I have ROOT_URL, TZ, and MAIL_URL like this:

{
    "ROOT_URL": "http://xxx.yyy/",
    "MAIL_URL": "smtp://postmaster@xxx.yyy:frommailgun@smtp.mailgun.org:25",
    "TZ":       "Australia/Sydney"
}

This works for me, NodeChef also allow you to set environment variables once deployed so you can update them later too.

1 Like

are you sure you’ve got this correct? why do you have ‘sandboxid.mailgun.org’ for the username?

1 Like

@cstrat @rlespagnol
I sure do appreciate your jumping in on this overnight. That bit of code is so old, :steam_locomotive: the fact of writing it is the only thing I remember about it.

hey @warehouseman, I posted my code (it’s just the json config from my deployment) and I think I quoted OPs env code. haven’t looked at what you posted but sounds like it’s similar…?

Yeah, what I said there was mainly directed to @rlespagnol, for actually reading my code :flushed:

1 Like

I should review my tests to see whether they actually test whether that bit still works :smirk:

@cstrat
I think so?!
In my mailgun dashboard for my sandbox domain it says:
Default SMTP Login: postmaster@sandboxABC123.mailgun.org
Default Password: abc123xyz

So that is how I came up with

export MAIL_URL="smtp://postmaster@sandboxABC123.mailgun.org:abc123xyz@smtp.mailgun.org:587"

is this not correct?!

Maybe you can crosscheck with your sandbox domain?! :slight_smile:

oh sorry, I have never used the ‘sandbox’ domain, I didn’t realise that is what you are using, i’ve always just used my own domain linked with MailGun. i’ve connected my custom domain (still just using the free plan).

the only other thing i noticed you’re using port 587, are you sure that port is allowed to make an outbound connection on your server? why not try to use port 25? (maybe the mailgun npm package uses port 25 and thats why its working).