Home > Software design >  Impossible to Send Multiple Emails from Gmail after May 30th Update
Impossible to Send Multiple Emails from Gmail after May 30th Update

Time:07-14

I have code which has remained essentially unchanged for months. The code extracted an email address and email password from an .env file and was used for a few difference cases. Whenever a single user signs up, they would receive an email; and whenever an owner signs many employees up, each of them would receive and email.

The email account we used to send these emails was a Gmail, and was created before the May 30th update and allowed less secure apps access. This allowed it to work sending an individual an email when they signed up, and provided there was a 1 second delay between each employee signed up, it was able to handle the en masse emailing as well.

The email account we use has since been changed, this new email was created after the May 30th update. I jumped through all of the extra hoops to enable less secured apps on this new account, so it sends individual sign up emails with no issue. However, as soon as I attempt to execute the en masse emails (even with the one second delay) I get the following error:

Error: Invalid login: 535-5.7.8 Username and Password not accepted.

Now, this really makes no sense because it is a copy and paste job of the email syntax that DOES work meaning this code below works...

try{
            // Creates the Transporter
            const transporter = nodemailer.createTransport({
                service: "Gmail",
                auth: {
                    user: `${process.env.SIGNUP_EMAIL}`,
                    pass: `${process.env.SIGNUP_PASS}`
                }
            })

            // Creates the Mail Object
            const mailOptions = {
                from: `${process.env.SIGNUP_EMAIL}`,
                to: `${actualEmail}`,
                subject: `Thank you for joining the TOM Team!`,
                text: `We have recieved your Account Signup and are please to welcome you to the TOM Experience!`
                }
            
            // Sends the mail
            transporter.sendMail(mailOptions, (error, response) => {
                if (error){
                    throw new Error('Something went wrong, please try again \n'   error)
                } 
            })
        } catch(error){
            console.log(error)
        }

But this code DOES NOT (breaks on the first attempt no matter how many others there are after)

try{
        const transporter = nodemailer.createTransport({
            service: "Gmail",
            auth: {
                user: `${process.env.SIGNUP_EMAIL}`,
                pass: `${process.env.SIGNUP_PASS}`
            }
        })
    
        // Creates the Mail Object
        const mailOptions = {
            from: `${process.env.SIGNUP_EMAIL}`,
            to: `${actualEmail}`,
            subject: `Thank you for joining the TOM Team!`,
            text: `We have recieved your Account Signup and are please to welcome you to the TOM Experience! \nUpon recieving this email, you will have a new TOM Account for the mobile app. Please use this email, and the password "${passwordToUse}" to login and get started!`
            }
        
        // Sends the mail
        transporter.sendMail(mailOptions, (error, response) => {
            if (error){
                console.log(error)
                throw new Error('Something went wrong, please try again \n'   error)
            } 
        })
    }
    catch(err){
        console.log(err)
        throw new Error(`Something went wrong emailing ${actualEmail}. Please check this is the proper address.`)
    }

Is it just impossible to send gmails en masse now? Even with a 1 second delay? Even if not, why is the very first email failing? I truly have no idea why I'm facing these errors

CodePudding user response:

I'm not sure why this is, but increasing the wait time from 1000 milliseconds to 1500, and then back to 1000 did the trick. I'm not sure, maybe the new email just needed to get baby-stepped into sending multiple at a time.

  • Related