Search code examples
firebasegoogle-cloud-firestoregoogle-cloud-functionsfirebase-extensions

Trigger email firebase extension - error with nodemailer


I installed the extension to trigger emails on databse writes. My website has a simple 'Contact me' form, where i'm not expecting a lot of traffic, so I wanted to set-up a simple notification e-mail system.

However, i'm having a hard time getting the confgiuration right.

I configured a firebase trigger e-mail extension:

smtp connection URI: smtp://email:password@smtp.gmail.net:465
email documents collection: messages
default FROM address: Some Name <email>

On every contact form submit, I store the data to firestore in a following format:

let db = firebase.firestore();
db.collection("messages").add({
    from: "First Last <email>",
    to: "email",
    replyTo: "First Last <email>",
    message: {
        subject: "New message from website!",
        text: "some text"
    }
})
.then((docRef) => {
    console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
    console.error("Error adding document: ", error);
});

Document gets written to Firestore.

The error I see in functions log:

ext-firestore-send-email-processQueue Error when delivering message=messages/vG9gviTCyh1Glxl1vBu1: Error: queryA EREFUSED smtp.gmail.net

Furthermore I see that Firestore collection has gotten a delivery object added to it with the same error.

Given the above, I think the code part is working - I successfully store the field in the Firestore and it triggers a cloud function. I think the issue is with configuration on either trigger email extension or in gmail settings.

Now, I didn't find much useful about this when googling (using GMAIL with Trigger email extension in firebase) and that's a hint that I may be off to a wrong start and perhaps should look into other options? If that's not the case, then what other settings may I check? I did create myself an app password in gmail, but I don't know where should I submit it in the trigger email extension. Would I also need to configure the gmail as a SMTP server in the Authentication templates configuration?


Solution

  • Breaking down the error message,

    • queryA - Submitting a query for a DNS A-Record
    • EREFUSED - Was refused (threw an error - e.g. not found)
    • smtp.gmail.net - the subject of the query

    So in short, this is saying the web server smtp.gmail.net could not be found as it isn't registered.

    Based on the documentation for sending email using Gmail,

    • If you are using a Google Workspace, you should use smtp-relay.gmail.com (10k daily message limit)
    • If you are a regular Gmail user, you should use smtp.gmail.com (2k daily message limit)

    If you plan on exceeding these limits, you should consider making use of a third-party mailing service.