简体   繁体   中英

How to send mail using nodemailer and Zoho mail?

I'm trying to setup ZOHO mail with Nodemailer. The mail is configured correctly and I'm using following code to send the mail, but still getting error in sending mail:

const nodemailer = require('nodemailer');

let from = `Company Name <contact@company.com>`

let transporter = nodemailer.createTransport({
    // host: "smtp-mail.gmail.com",
    host: 'smtp.zoho.com',
    port: 465,
    secure: true,
    auth: {
        user: "contact@company.com",
        pass: "mypassword"
    }
});

// Mail response to User
        const mailResponse = {
            from: from,
            to: `userName`,
            subject: "📞 Thanks For Connecting With Company Name",
            html: // mail body
}


 try {
            
            await transporter.sendMail(mailResponse);

            res.status(200).json({ message: "Message Sent" });
        } catch (err) {
            res.status(400).json({ message: "Unexpected Error!!! Please try again" });
        }

Please let me know how can I fix this issue. i have tried every possible solution given on website.

Try this -

service: "gmail",
host: "smtp.gmail.com",
auth: {
    user: "username@company.com",
    pass: "yourpassword"
}

At the place of user put your email and in pass but your password or you can get these from env to be safe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM