| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
aiguang
10年前发布

Nodejs使用mailer发送邮件

在实际应用中,有时需要服务器有特点的信息时及时的推送消息给你,而让你有所准备和处理,项目中服务器的个数比较多,所以管理服务器集群也不是很方便,我就是每台服务器上出现异常退出的时候都发送邮件到我的邮箱同时并重新启动Nodejs服务器。

废话不多说,实例上之:

首先,需要安装一个发送邮件的模块:

npm install mailer

然后在代码中引入模块:

var email = require("mailer");

最后使用模块发送邮件:

email.send(          {              ssl: true,              host: "smtp.exmail.qq.com",//发送 smtp.qq.com,接收 pop.qq.com              domain: "[xxx.xxx.xxx.xxx]",//可以在浏览器中输入 http://ip.qq.com/ 得到              to: "xxx@qq.com",              from: "xxx@xxx.com",              subject: "myemail test email",  //            reply_to: "xxx@xxx.com",              body: "Hello! This is a test of the myemail.",              authentication: "login",              username: "xxx@xxx.com",              password: "xxx",              debug: false          },          function (err, result) {              if (err) {                  console.log("the err:" + err);                  response.write(JSON.stringify({                      "提示信息": "发送失败",                      "失败原因": "数据异常"                  }));                  response.end();              } else {                  if (result) {                      console.log("发送成功");                      response.write(JSON.stringify({                          "提示信息": "发送成功"                      }));                      response.end();                  } else {                      response.write(JSON.stringify({                          "提示信息": "发送失败",                          "失败原因": "数据异常"                      }));                      response.end();                  }              }          }      );

Nodejs这个模块简单易用,希望对你有所帮助。

代码下载:http://download.csdn.net/detail/qxs965266509/8896463

希望可以帮助到大家,对你有帮助或者觉得值得借鉴的,可以在下方点个赞!谢谢!!!
如有转载请著名来自http://blog.csdn.net/qxs965266509