1. 安装sendmail

参考: http://www.server110.com/sendmail/201311/3289.html

yum -y install sendmail

2. 配置 /etc/mail/sendmail.mc

DAEMON_OPTIONS('Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

替换为为

DAEMON_OPTIONS('Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

末行加上

MAILER(local)dnl

让sendmail本地用户的邮件不通过SMTP,直接在服务器上传送。

然后重启sendmail

service sendmail start

3. 安装node模块

npm install sendmail

4. 发邮件代码

var sendmail = require('sendmail')();

sendmail({
    from: 'no-reply@wenglou.com',
    to: 'youremail@xxx.com',
    subject: '测试邮件哦',
    content: '请不要回复,这是一个测试内容',
  }, function(err, reply) {
    console.log(err && err.stack);
    console.dir(reply);
});