【问题标题】:Nodemailer and postfixNodemailer 和后缀
【发布时间】:2021-05-19 03:38:23
【问题描述】:

我已经将带有默认参数的 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)});

在 tail -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,邮件发送添加我收到它。 一些想法为什么?

【问题讨论】:

  • 您是否测试过使用postfix 发送电子邮件?
  • 是的,我将它添加到帖子中 - 但如果我使用命令echo "First message" | mutt -s "msg" mymail@mail.ru,邮件发送添加我收到它。
  • 我认为可能与您的postfix 配置有关。也许研究一下为什么客户端在发送EHLO 消息后会失去连接。这里不是postfix 专家,帮不上忙。

标签: node.js nodemailer postfix-mta


【解决方案1】:

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

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);
  }
});

【讨论】:

  • 你从哪里得到service的选项?
猜你喜欢
  • 2016-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-27
  • 2020-07-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多