Nodemailer和后缀

时间:2019-01-30 01:01:32

标签: node.js nodemailer postfix-mta

我已将具有默认参数的postfix安装为Internet站点,并将nodemailer软件包安装到我的node.js服务器中。并尝试这样做:

var transporter = nodemailer.createTransport({
    host: '127.0.0.1',
    port: 25,
    // auth: {
    //     user: user,
    //     pass: pass
    // },
    secure: false,
    tls:{
        rejectUnauthorized: false
    }
});

我不知道用户名和密码是什么,我没有设置。

transporter.sendMail({
            from: '"Mysite.com" <robot@mysite.com>', // sender address
            to: user.email, // list of receivers
            subject: "Your password for mysite.com", // Subject line
            html: html // html body
        }, (err) => {console.log('mail send error', err)});

在尾部-f /var/log/mail.log中,我看到了

Jan 30 01:00:04 80523 postfix/smtpd[26772]: connect from localhost[127.0.0.1]
Jan 30 01:00:04 80523 postfix/smtpd[26772]: lost connection after EHLO from localhost[127.0.0.1]
Jan 30 01:00:04 80523 postfix/smtpd[26772]: disconnect from localhost[127.0.0.1] ehlo=2 starttls=1 commands=3

邮件未发送... 但是,如果我使用命令echo "First message" | mutt -s "msg" mymail@mail.ru,则发送的邮件加上我也会收到。 为什么有一些想法?

1 个答案:

答案 0 :(得分:0)

如果您按照此处找到的类似后缀设置:

https://medium.com/codingtown/send-mail-using-postfix-server-bbb08331d39d

然后你应该能够得到以下运行

const nodemailer = require('nodemailer');

let transporter = nodemailer.createTransport({
  service: 'postfix',
  host: 'localhost',
  secure: false,
  port: 25,
  auth: { user: 'yourlinuxusername@edison.example.com', pass: 'yourlinuxuserpassword' },
  tls: { rejectUnauthorized: false }
});

let mailOptions = {
  from: 'yourlinuxusername@edison.example.com',
  to: 'xxxyyyzzz111@gmail.com',
  subject: 'nodemailer test',
  text: 'hope it got there'
};

transporter.sendMail(mailOptions, (error, info) => {
  if (error) {
    console.log(error);
  } else {
    console.log(info);
  }
});