nodemailer 发邮件

var transporter = nodemailer.createTransport({//v1.0 above do not use 'SMTP' as first param
            host: "smtp.xxx.xxx.com",
            port: 25,
            name:"xx.xx.com",
            tls: {
                rejectUnauthorized:false,
            },
            auth: {
                user: user,
                pass: password
            }
        });

        // setup e-mail data with unicode symbols
        var mailOptions = {
            date: new Date(),
            from: 'noreply@xxx.xxx.com', // sender address
            to: 'xxx@xxx.com, xxx@qq.com,', // list of receivers
            subject: title, // Subject line
            text:content,
            html: '<div>'+content.replace(/[\r\n]+/g,'<br />')+'</div>' // html body
        };

        var msg = yield function(fn){
            // send mail with defined transport object
            transporter.sendMail(mailOptions, function(error, info){
                var msg='';
                if(error){
                    msg = 'sendMail fail>>>'+error;
                }

                msg = 'Message sent: ' + (info&&info.response);
                transporter.close();
                fn(error,msg);
            });
        }

  KOA 项目内,使用 co 框架扁平化回调函数 

 

文档:

http://nodemailer.com/2-0-0-beta/setup-smtp/

转载于:https://www.cnblogs.com/ecalf/p/5597280.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值