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

Trigger email extension stuck when using Gmail/Gsuite to send emails #41

Closed
aq2 opened this issue Oct 13, 2019 · 39 comments
Closed

Trigger email extension stuck when using Gmail/Gsuite to send emails #41

aq2 opened this issue Oct 13, 2019 · 39 comments
Assignees
Labels
good first issue Good for newcomers in-progress A fix or resolution is in progress

Comments

@aq2
Copy link

aq2 commented Oct 13, 2019

Hi - not sure if this is the right place for support, but here goes...

My emails are stuck in 'PROCESSING' mode

firebase-mail

i'm using gmail to send my mails, using smtp://me@gmail.com:password@smtp.gmail.com:465

what am i doing wrong?

thanks in advance

@Ehesp
Copy link
Member

Ehesp commented Oct 14, 2019

Hi @aq2 - Would you be able to check the Firebase Functions logs to see if any error is occurring?

@Ehesp Ehesp added the type: bug Something isn't working label Oct 14, 2019
@Ehesp Ehesp self-assigned this Oct 14, 2019
@aq2
Copy link
Author

aq2 commented Oct 14, 2019

okay thanks,

i'm just testing this with a simple button on my website that adds a document to my 'mail' collection

i press the button, see the new doc in the collection, but it stays at 'processing' - no errors shown in 'delivery' field - just says 'null' and 0 attempts

logs don't seem to give any obvious error messages, but it eventually times out

i'm not sure what you want to see...
fb-logs

@rphlmr
Copy link

rphlmr commented Oct 16, 2019

@aq2 Hello :)
I don't see an "smtpConnectionUri" on your extension's configuration. Is it normal ?

@Ehesp
Copy link
Member

Ehesp commented Oct 16, 2019

@rphlmr It's omitted as it's a sensitive field.

I'll try this out myself using my own Gmail account as the SMTP provider. My initial thinking is that node-mailer is forever trying to connect to the SMTP server and eventually timeout the function.

@aq2 would you be able to try smtps:// rather than smtp://? The Gmail SMTP server requires SSL by the looks of it.

@rphlmr
Copy link

rphlmr commented Oct 16, 2019

@Ehesp oh yes 🤦‍♂️
If it can help @aq2 , I have this config (working):
smtps://me@mydomain.app:verycomplicatedpassword@my.smpt.provider:465

@aq2
Copy link
Author

aq2 commented Oct 16, 2019

hi - thanks for your inputs,

I have managed to get it working using a different email provider, but am still unable to use with gmail, whether using smtp or smtps

I have heard that gmail are quite a large email company and i am surprised that i can't get the extension working with them.

@Ehesp did you manage to get gmail working?

@Ehesp
Copy link
Member

Ehesp commented Oct 17, 2019

Could you try setting the from address as your own email used for Gmail?

@aq2
Copy link
Author

aq2 commented Oct 17, 2019

sorry, not quite sure what you mean

i've been using the same email address in 'from' and smtp URI - ie my gmail address

or are you suggesting that i use gmail URI, but with a different from address - like 'send as'?

@aq2 aq2 closed this as completed Oct 17, 2019
@aq2
Copy link
Author

aq2 commented Oct 17, 2019

sorry - pressed the wrong button - didn't mean to close - whoops

@aq2 aq2 reopened this Oct 17, 2019
@Ehesp
Copy link
Member

Ehesp commented Oct 17, 2019

That's ok then, I believe Gmail has restrictions around the from sender address having to be the same as the SMTP user.

Let me try and get Gmail sync'd up and I'll get back to you on whether I can get it working.

@Ehesp Ehesp added good first issue Good for newcomers and removed type: bug Something isn't working labels Oct 22, 2019
@Niweera
Copy link

Niweera commented Oct 26, 2019

I have came across the same issue as the op. However, I tried with my gmail and it worked. (example@gmail.com). But I tried with a GSuite email (example@customdomain.com) and it did not work for that email. The delivery state is stuck on PROCESSING and the cloud function is timing out after one minute. Any suggestion is appreciated.
Thanks in advance.

@timsewell
Copy link

I am also having this issue. I've also now tried it with a Yahoo mail account and the same thing happens.
My function config:
image
(NB, I've also tried with smtps using port 587. I've tried with the normal account password and with a generated app-specific password. I'm kind of tearing my hair out here, so any help from anyone who has overcome this with any decent email provider would be extremely welcome. Thanks!

@timsewell
Copy link

So, I don't think this is an issue with the email provider. I knocked up a quick and dirty nodemailer app and it worked perfectly with the same account details.

@Ehesp
Copy link
Member

Ehesp commented Oct 30, 2019

What Firebase plan are you on? Trying to replicate in the same environment.

@timsewell
Copy link

Blaze

@timsewell
Copy link

Hi @Ehesp - thanks for helping me with this. Further info - I've set up a custom function, triggered from the same collection, that uses nodeMailer to send the required emails and it works fine using my email account details that weren't working with the ready-made email trigger. I've had a look at the source of the ready-made one and nothing jumps out at me. Could it be to do with the way the smtp url string is being parsed? I notice that the collection document gets updated with attempts: 0, whatever config etc I tried and even when errors were reported.

@barrylachapelle
Copy link

I had the same issue - my challenge was that my email was a GSuite account and I needed to allow access from Less Secure Apps. I had to go into my GSuite account, Security allows Users to Set own Less Secure Apps. Then set it for my email.

It was a bit of a struggle but I hope that helps someone.

@timsewell
Copy link

I couldn't do that with my initial email account as it has 2FA. However, I followed the various instructions for that, including an app-specific password and didn't have any joy. Then I set up another GMail account without 2FA and followed the allow-less-secure and recaptcha settings - still didn't work. It's the latter account that I have working fine, now, with my own cloud function. It's weird how this seems to work for some users and not for others.

@ctwhome
Copy link

ctwhome commented Nov 4, 2019

I have the same problem with the GSuite account. I allowed access from Less Secure Apps but nothing. It doesn't work. I have also tried all possible combinations with port 587 and without it.
image

@ctwhome
Copy link

ctwhome commented Nov 4, 2019

If it helps, what I did for GMAIL account:
smtps://namel@gmail.com:pass@smtp.gmail.com:465
and then a enable "Less secure app access"
https://myaccount.google.com/u/2/lesssecureapps

I didn't manage to use my GSuite account tho yet.

@timsewell
Copy link

Thanks - and I'm glad you got it working. I've found that my custom cloud function does everything I need it to do, so I've moved on to other areas of functionality.

@logemann
Copy link

logemann commented Nov 6, 2019

For all fighting with the correct connection URL, it might help to consult nodemailer documentation. https://nodemailer.com/smtp/

The extension just passes the connection URL as is to nodemailer. I stopped trying with gmail cause of 2FA. Testing can be better done with mailservices like sendgrid or mailgun. They have free plans and offer a SMTP gateway which one can use.

@ctwhome
Copy link

ctwhome commented Nov 8, 2019

For all fighting with the correct connection URL, it might help to consult nodemailer documentation. https://nodemailer.com/smtp/

The extension just passes the connection URL as is to nodemailer. I stopped trying with gmail cause of 2FA. Testing can be better done with mailservices like sendgrid or mailgun. They have free plans and offer a SMTP gateway which one can use.

Isn't it the idea of the extension to handle this without extra impediments?

@Niweera
Copy link

Niweera commented Nov 12, 2019

For those who are still struggling with GSuite emails for the Email Trigger Extension. I think I may have found a solution. As the OP says I was stuck at the PROCESSING state and nothing happened when I gave the smtps URI as smtps://username@customGSuiteDomain.tld:veryComplicatedPassword@smtp.gmail.com:465.

However when I used a password without any special characters it worked.
NB: The following settings were set for the GSuite email account.

I have the same problem with the GSuite account. I allowed access from Less Secure Apps but nothing. It doesn't work. I have also tried all possible combinations with port 587 and without it.
image

@ctwhome pls try this and find out whether it worked for you or not.

@MatteoStohlman
Copy link

However when I used a password without any special characters it worked.

I URL encoded the special characters in my password and that worked fine.

Have it working with

  1. Less secure apps setting
    68124025-ac7cdd00-ff0e-11e9-8f1a-3871b17cf3b2

  2. SMTP Server
    smtps://username@customGSuiteDomain.tld:veryComplicatedPassword%21%0A@smtp.gmail.com:465

NB. from email same as auth email although idk if that is necessary

@Niweera

@Niweera
Copy link

Niweera commented Nov 18, 2019

@MatteoStohlman yeah, I did the same. It's working fine for me.

@ravpacheco
Copy link

Hi guys, any update about this issue?

@shaisa
Copy link

shaisa commented Dec 15, 2019

Had the same issue until I encoded the password - you can check it here to make sure https://www.urlencoder.org/

@ravpacheco
Copy link

ravpacheco commented Dec 16, 2019

Hi @shaisa, I had not only encoded the password but also changed to a simple password, without special character.

I believe google functions has some problem to execute Nodemailer with a provider different than Google. When I try to send an email with my email provider anything works.

I have tried locally with Firebase Functions Emulator and in a vanilla Node.js. The code works fine in a vanilla node.js application but doesn't work with Firebase Function.

@shaisa
Copy link

shaisa commented Dec 16, 2019

Mmmm.... You know what - I couldn't make the extension to work with my g-suite smtp-relay as well...
I guess gmail is the only one working right now. And the logs are worthless to understand why.

If only someone from google was here to help ;)...

@mbleigh
Copy link
Collaborator

mbleigh commented Dec 16, 2019 via email

@shaisa
Copy link

shaisa commented Dec 16, 2019

Of course - at least on my end this is not the case - this is a part of evaluating the extension in terms of usability and limitations (btw, not all use cases are for mass mailing so I wouldn't dismiss this issue because of that).
When something doesn't work without understanding why - it is a sign for me that there might be more "black holes" down the road and I take it into consideration before moving it to production.
Maybe it's a good idea to add a log when this error occurs in the extension or a known issue somewhere to notify people of this bug (/feature). Even a small "G Suite smtp-relay is not supported" message in the configuration GUI / CLI would do the job and save time for people trying it...

@ctwhome
Copy link

ctwhome commented Dec 17, 2019

Hi! After all the services that firebase provides to create extremely fast, complex, realtime applications... Having to use a third party like sendgrid to handle emails seems odd to me. I mean, for an application sending emails to customers is fundamental, why is this not being part of the core functionalities of firebase? Maybe firebase hosting?

@laurenzlong laurenzlong changed the title trigger email extension trigger email extension stuck when using Gmail/Gsuite to send emails Dec 17, 2019
@laurenzlong laurenzlong changed the title trigger email extension stuck when using Gmail/Gsuite to send emails Trigger email extension stuck when using Gmail/Gsuite to send emails Dec 17, 2019
@laurenzlong
Copy link
Contributor

Hi, we are not planning to offer an email service within Firebase in the forseeable future.

It seems like the workaround in #41 (comment) is the best approach. Perhaps we can document this more clearly.

@bdiz
Copy link

bdiz commented Sep 10, 2020

I don't think it's a gmail/gsuite specific issue. I am getting an indefinite PROCESSING status with Postmark. My smtp URI looks like smtp://abcdef-1234:abcdef-1234@smtp.postmarkapp.com:25. Postmark uses an api key with only hex characters and dashes so special characters doesn't seem like it would be the issue in my case. The password and username for postmark are the same.

I tried this smtp URI with nodemailer in a node repl locally and I was able to send an email successfully so it doesn't seem to be Postmark.

I previously was using SendGrid with this extension and I had emails working.

Complicating my debug data is I upgraded the extension from node 8 to node 10, but I'm not sure that has anything to do with seeing this issue since I never tried Postmark on node 8. Nor have I tried SendGrid on node 10. Trying to reactivate my SendGrid account to see if I can get that working again (they deactivated me without notice (I'm thinking due to low volume), which is what sent me on this goose chase in the first place).

@bdiz
Copy link

bdiz commented Sep 10, 2020

Trying to debug the function. Upon the create of the initial document the cloud function updates attempts to 0 and state to PENDING. But what I see when observing the document in the firebase console is attempts are 0 and state is PROCESSING.

Looking at the switch statement for PENDING, it sets state to PROCESSING and then should call deliver().

case "PENDING":
case "RETRY":
// Wrapping in transaction to allow for automatic retries (#48)
await admin.firestore().runTransaction((transaction) => {
transaction.update(change.after.ref, {
"delivery.state": "PROCESSING",
"delivery.leaseExpireTime": admin.firestore.Timestamp.fromMillis(
Date.now() + 60000
),
});
return Promise.resolve();
});
return deliver(payload, change.after.ref);

However, if deliver() was called at all, why would attempts remain 0? My logs confirm that the "Attempting delivery..." message is not present either.

These observations match with earlier reports: The original post shows attempts 0 (#41 (comment)). and a later comment shows a log that does not have a "Attempting delivery..." message (#41 (comment)).

Is there something with await admin.firestore().runTransaction where it might be hanging there (though update of state to PROCESSING goes through)? I see there is a comment in the code about issue #48. Not sure if the issues there are still causing issues with this firebase extension.

@Ehesp can we reopen?

@bdiz
Copy link

bdiz commented Sep 19, 2020

@Ehesp , do you want me to file a new bug? Node 10 simply won't send an email for me.

@L96Github
Copy link

Also had this problem and removing the special characters from the password worked for me as well! Thanks 🙏🏽

@manglide
Copy link

manglide commented Jun 7, 2021

I also had the same issue, trying to send with a gmail account (not G-Suite).

What worked:

  1. Allow less secure apps on the gmail account - https://myaccount.google.com/lesssecureapps
  2. URL encoding your password with https://www.urlencoder.org/ if it has special characters.

The above 2 steps did the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers in-progress A fix or resolution is in progress
Projects
None yet
Development

No branches or pull requests