nodemailer 发邮件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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/

posted @   ecalf  阅读(218)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示