Need email Notification service using smtp,using Nodemailer

情到浓时终转凉″ 提交于 2021-01-28 06:09:01

问题


I am trying to implement Nodemailer for sending one or bulk emails but facing trouble to handle when there is a failure in sending email for eg. Email Address not found. I need a list of these bounced emails and other such failures and insert them into the DB,after trying to send the email twice.

Below is my code:

const nodemailer = require("nodemailer");

var smtpConfig = nodemailer.createTransport(
    {
        host: hostname,
        port: port,
        secure: false,
        auth: {
            user: username,
            pass: password
        },
        logger: false,
        debug: false
    },
    {
        headers: [],
        priority: "normal"
    }
);

function sendMailnew() {
    const mailOptions = {       
        from: "email.com,
        to: "sjdhf@jhdf.com",
        subject: "my testing emails new",
        html: "my testing email",
        dsn: {
            id: "123",
            return: "HEADERS",
            notify: ["failure", "delay"],
            recipient: "abc@gmail.com"
        }
    };
    smtpConfig.sendMail(mailOptions, function(error, response) {
        if (error) {
            console.log(error);
        } else {
            console.log("mail sent");
        }
    });
}

sendMailnew();

I am using gmail SMTP. Please Help.Thanks!Let me know if any more details are needed.

来源:https://stackoverflow.com/questions/50504101/need-email-notification-service-using-smtp-using-nodemailer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!