node.js发送邮件email

来源:互联网 发布:用户登录sql注入 编辑:程序博客网 时间:2024/06/05 07:09

首先我们还是得安装node的第三方用户发送email的依赖module 。

npm install nodemailer

安装好之后,还有一个问题需要注意,我们应该确保用来发送邮件的邮箱地址是打开只是IMAP 、SMTP功能的,这样才可以发送邮件成功。

//发送邮件mail.SMTP = {    use_authentication: true, //如果我们使用QQ等邮箱,这个必须写且为true    host: 'smtp.qq.com', //定义用来发送邮件的邮箱服务器,一般是QQ这些的    port: 25, //定义服务器端口,一般是25   ,如果是使用SSL端口一般为465,或者587    ssl: false, //默认不适用SSL,可以省略不写    user: '123456@qq.com', //邮箱用户名    pass: '*****'   //输入邮箱密码}mail.send_mail(        {            sender: '123456@qq.com', //发送邮件的地址            to: '34343@qq.com', //发给谁            subject: '邮件标题', //主题            body: '内容部分'        },        //回调函数,用户判断发送是否成功,如果失败,输出失败原因。        function(error, success) {            if (!error) {                console.log('message success');            } else {                console.log('failed' + error);            }        }); 

转载自:http://www.9958.pw/post/nodemailer

0 0