Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception thrown when calling forgot password with --production flag and MAIL_URL set #11709

Open
santiagopuentep opened this issue Oct 21, 2021 · 8 comments · May be fixed by #11710
Open

Exception thrown when calling forgot password with --production flag and MAIL_URL set #11709

santiagopuentep opened this issue Oct 21, 2021 · 8 comments · May be fixed by #11710

Comments

@santiagopuentep
Copy link

@santiagopuentep santiagopuentep commented Oct 21, 2021

On Meteor 2.4, calling Accounts.forgotPassword with the --production flag active and MAIL_URL is set with real keys throws this exception:

Exception while invoking method 'forgotPassword' TypeError: Cannot read property '_syncSendMail' of null
    at smtpSend (packages/email/email.js:154:13)
    at Object.Email.send (packages/email/email.js:233:5)
    at Object.Email.send (packages/mdg:meteor-apm-agent/lib/hijack/email.js:10:28)
    at AccountsServer.Accounts.sendResetPasswordEmail (packages/accounts-password/password_server.js:667:9)
    at MethodInvocation.forgotPassword (packages/accounts-password/password_server.js:478:12)
    at MethodInvocation.methodMap.<computed> (packages/mdg:meteor-apm-agent/lib/hijack/wrap_session.js:161:30)
    at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1885:12)
    at packages/ddp-server/livedata_server.js:769:19
    at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1257:12)
    at packages/ddp-server/livedata_server.js:767:46
    at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1257:12)
    at packages/ddp-server/livedata_server.js:765:46
    at new Promise (<anonymous>)
    at Session.method (packages/ddp-server/livedata_server.js:739:23)
    at packages/mdg:meteor-apm-agent/lib/hijack/wrap_session.js:52:38
    at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1257:12)
    at Session.sessionProto.protocol_handlers.method (packages/mdg:meteor-apm-agent/lib/hijack/wrap_session.js:51:44)
    at packages/ddp-server/livedata_server.js:603:43

smtpSend() receives no transport, and there's no check of existence before calling one of it's function.

Expected behavior:

No exception should be thrown.

@StorytellerCZ
Copy link
Contributor

@StorytellerCZ StorytellerCZ commented Oct 21, 2021

Is there any way you can reproduce this issue without the --production flag?

@StorytellerCZ StorytellerCZ linked a pull request that will close this issue Oct 21, 2021
@StorytellerCZ StorytellerCZ linked a pull request that will close this issue Oct 21, 2021
@StorytellerCZ
Copy link
Contributor

@StorytellerCZ StorytellerCZ commented Oct 21, 2021

Also please try out #11710 if that fixes your issue or not (I don't think so, but one never knows).

@StorytellerCZ
Copy link
Contributor

@StorytellerCZ StorytellerCZ commented Oct 26, 2021

@santiagopuentep can you please test #11710 to see if it fixes your issue, so that we can move forward in releasing it?

@megawebmaster
Copy link

@megawebmaster megawebmaster commented Nov 15, 2021

@StorytellerCZ - I believe this is caused by missing mail setup in production mode. In this commit c704a16 there is a change that removed check for transport being non-null before calling smptSend.

Do you know why was this change introduced?

@santiagopuentep
Copy link
Author

@santiagopuentep santiagopuentep commented Nov 15, 2021

Sorry, I didn't see the notifications for this. How do I test the code?

@DerGut
Copy link

@DerGut DerGut commented Nov 16, 2021

We are getting the same error from a Accounts.sendVerificationEmail call:

TypeError: Cannot read property '_syncSendMail' of null
 at smtpSend (packages/email/email.js:154:13)
 at Object.Email.send (packages/email/email.js:233:5)
 at AccountsServer.Accounts.sendVerificationEmail (packages/accounts-password/password_server.js:687:9)

Interestingly, this error only occurs in our CI test jobs running meteor test --once --driver-package meteortesting:mocha without any environment. We weren't yet able to replicate it locally.

@megawebmaster
Copy link

@megawebmaster megawebmaster commented Nov 16, 2021

@DerGut - the same happens to me and it is because Meteor changed how they check for mail transport. If you run it in a production-like env it is enough, so if you don't supply a correct MAIL_URL then you'll get this error.

As I'm using Docker Compose to run the test I just added another service (mailcatcher) and pointed Meteor mailer there. It was enough to make it work 😉

@DerGut
Copy link

@DerGut DerGut commented Nov 16, 2021

@megawebmaster Thanks for the info! But I don't even understand why smtpSend is invoked instead of devModeSend in the first place. Looking at

if (Meteor.isProduction || process.env.MAIL_URL || Meteor.settings.packages?.email) {
const transport = getTransport();
smtpSend(transport, options);
return;
}
devModeSend(options);
, none of Meteor.isProduction, MAIL_URL or Meteor.settings.packages?.email should be truthy in my case 🤔 .

At least I don't run the tests with a --production flag or have any NODE_ENV=production or MAIL_URL=<some url> environment variables set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants
@santiagopuentep @megawebmaster @StorytellerCZ @DerGut and others