阿里云企业邮箱使用nodemailer,使用nodemailer发送错误信息

最近在使用node做服务端开发,想在node运行出错时,可以及时发送邮件,以方便处理错误,于是用到了nodemailer。

使用nodemailer发送邮件,阿里企业云邮箱各个服务器地址及端口信息如下:

收件服务器地址:

POP 服务器地址:pop3.mxhichina.com 端口110,SSL 加密端口995

IMAP 服务器地址:imap.mxhichina.com 端口143,SSL 加密端口993

发件服务器地址:

SMTP 服务器地址:smtp.mxhichina.com 端口25, SSL 加密端口465

const nodemailer = require('nodemailer');

nodemailer.createTestAccount((err, account) => {

    let transporter = nodemailer.createTransport({
        host: 'smtp.mxhichina.com',
        port: 25,
        secure: false, // true for 465, false for other ports
        auth: {
            user: '[email protected]', // 邮箱账号
            pass:  '*******' // 邮箱密码
        }
    });

    // setup email data with unicode symbols
    let mailOptions = {
        from: '<[email protected]>', // 发件人地址
        to: '[email protected],[email protected],[email protected]', //收件人列表
        subject: 'Hello', // 主题
        //text: 'Hello world?', // plain text body
        html: '<b>Hello world?</b>', // html body
        attachments:[{//上传附件,可以直接使用文件作为附件,也可以使用content指定文本作为附件
            filename:'spider.js',
            path:'./spider.js'
        },{
            filename:'ErrorInfo.txt',
            content:'错误信息'
        }]
    };

    // 发送邮件
    transporter.sendMail(mailOptions, (error, info) => {
        if (error) {
            return console.log(error);
        }
        console.log('Message sent: %s', info.messageId);

        console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
    });
});

猜你喜欢

转载自blog.csdn.net/w20101310/article/details/78720496
今日推荐