NaomiCreate / cnss-app

0 stars 0 forks source link

Sending emails from remote server #40

Open mavishak opened 3 years ago

mavishak commented 3 years ago

We succeeded to send email's running our script locally. But we had problems running them remotely:

This is the error message we got in the firebase log:

Error: Invalid login: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt

Steps we took:

  1. In index.js:

    const mailTransport = nodemailer.createTransport({
        service: 'gmail',
        auth: {
          user: SENDER_EMAIL,
          pass: SENDER_PASSWORD,
        },
      });
  2. Allowing less secure apps into the SENDER_EMAIL account. https://myaccount.google.com/lesssecureapps

  3. Allowing access to the SENDER_EMAIL account. Set SENDER_EMAIL to your default account. https://accounts.google.com/b/0/DisplayUnlockCaptcha

This link helped: Nodemailer with Gmail and NodeJS

Problem: It seems that access to SENDER_EMAIL account is not permanent. I didn't find what triggers it - It might be a timeout or that I mistakingly issued an access removal somehow.

Possible solution Nodemailer addresses this issue and recommends using a different provider. see:

One other thing It might be better to trigger a .onCreate event rather than .onWrite - in order to minimize the function calls and the threatening caust

mavishak commented 3 years ago

Problem The average time to send the emails out is 4 minutes (one lucky time it took 1 minute).

Problem solved We sent out a question in stackoverflow https://stackoverflow.com/questions/68146035/how-to-reduce-email-sending-time-using-nodemailer-and-firebase