2

I currently have a site using Nodemailer & Gmail that works fine in my local development environment - any email sends instantly to the desired address.

Sadly, in production, only the admin notifications are being sent and the user ones are taking a very long time to deliver or not delivering at all. Ones that have arrived successfully took around 1 hour. The receiving email for admin emails is of the same domain as the URL of the website which makes me consider whether it's a domain verification issue. Only external recipients seem to get the delay.

My code is as follows:

const nodemailer = require('nodemailer')

const gmailUser = process.env.GMAIL_USER
const gmailPass = process.env.GMAIL_PASS
const appTitle = process.env.APP_TITLE
const receivingEmail = process.env.MAIL_RECEIVE

const smtpTransporter = nodemailer.createTransport({
    host: 'smtp.gmail.com',
    port: 465,
    secure: true,
    auth: {
        user: gmailUser,
        pass: gmailPass
    }
})

const emailConfirmation = (userEmail) => {
    const userMailOptions = {
        from: appTitle,
        to: userEmail,
        subject: `${appTitle} - User Confirmation`
        text: 'User Confirmation'
    }
    const adminMailOptions = {
        from: appTitle,
        to: receivingEmail,
        subject: `${appTitle} - Admin Confirmation`,
        text: 'Admin Confirmation'
    }

    Promise.all([
        smtpTransporter.sendMail(userMailOptions),
        smtpTransporter.sendMail(adminMailOptions)
    ])
        .then((res) => { return true })
        .catch((err) => { console.log("Failed to send email confirmations: ", err); return false })
}

I then call the function in a POST handler as follows:

emailConfirmation(user.email)

Am I doing something wrong in my code, or is this likely to be some sort of domain verification error?

ld98
  • 120
  • 1
  • 9
  • UPDATE: As per the Gmail interface, I can see that emails are being sent when requested (in the 'sent items' list, at the correct time) however the user is receiving the email around 1-2 hours later. – ld98 Feb 04 '23 at 06:51
  • Can you test with a personal email account, external to your domain, and share the headers? The Authentication-Results header particularly can tell you more about domain verification experience by the receiving server. Is Nodemailer DKIM signing on behalf of your sender domain? Is the Gmail SPF included in your domain SPF record? – Reinto Feb 04 '23 at 11:53
  • @Reinto thanks for your comment, I ended up switching to a different mail provider to save myself the headache. I did all the required verification processes, included the Gmail SPF record etc, all to no luck unfortunately. On the plus side, it is now working with the new provider :) – ld98 Feb 06 '23 at 06:25

1 Answers1

1

I ended up deciding to switch to a different mail provider and have since had no issues.

ld98
  • 120
  • 1
  • 9