0

I am trying to send a mail using Firebase Functions from an onCreate trigger using nodemailer and Zoho mail account. This is the entire function

export const mailFunc = functions.database.ref('/data/{messageId}')
.onCreate((snapshot, context) => {
    const data = snapshot.val();

    const transporter = nodemailer.createTransport({
        service: "Zoho",
        auth: {
            user: 'name@mydomain.in',
            pass: 'passwordgoeshere'
        }
    });

    const mailOptions: nodemailer.SendMailOptions = {
        from: 'name@mydomain.in',
        to: 'someone@gmail.com',
        subject: 'Here goes the subject',
        text: `${data.message}\n\n${data.name}`
    };

    return transporter.sendMail(mailOptions)
});

The thing is when I run this function with an invalid username or password it gives Error: Invalid login and when I try it with the correct username and password it gives the below error log

Error: getaddrinfo ENOTFOUND smtp.zoho.com
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

For reference

  • Using Firebase free plan (Spark Plan)
  • Haven't connected the custom domain yet
  • Using Zoho Free Plan
  • The password contains special characters(it's mandatory in Zoho)
  • Haven't changed any settings in the Zoho account other than the initial setup(Mail is working properly)

I am just getting started with Firebase and Node. I think the reference points may help. I am really stuck please help.

Ajay Sivan
  • 2,807
  • 2
  • 32
  • 57
  • 1
    The free "Spark" plan "allows outbound network requests only to Google-owned services". See https://firebase.google.com/pricing/ (hover your mouse on the question mark located after the "Cloud Functions" title). You need to switch to the "Flame" or "Blaze" plan. – Renaud Tarnec Mar 21 '19 at 09:44
  • @RenaudTarnec Thank you for your response. Is it possible to use a Gmail account instead of Zoho account on the free spark plan? – Ajay Sivan Mar 21 '19 at 09:46
  • Yes it is, but note that Gmail has an email sending quota: maximum of 500 recipients in a single email and maximum of **500 emails in a day sent**, see https://support.google.com/mail/answer/22839. Now, you have to know that the "Flame" or "Blaze" plans have a generous free tier. – Renaud Tarnec Mar 21 '19 at 09:52
  • @RenaudTarnec Okay thank you. If you post it as an answer I will accept it – Ajay Sivan Mar 21 '19 at 10:03
  • You are welcome. Better keeping the link to the duplicate question/answer (https://stackoverflow.com/questions/55061496/ipfs-module-not-working-with-firebase-functions) and avoid creating a new answer. I guess it is you who just upvoted the answer there, and I'm already happy with the 10 points I got :-) thanks – Renaud Tarnec Mar 21 '19 at 10:06
  • 1
    @RenaudTarnec Yes that's me. Happy coding. – Ajay Sivan Mar 21 '19 at 10:08

0 Answers0