2

I have install postfix with default parameters as Internet site, nodemailer package into my node.js server. And trying to do this:

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

I dont know what is username and password, I did not set it.

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

In tail -f /var/log/mail.log I see this

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

And mail is not sent... But if I use command echo "First message" | mutt -s "msg" mymail@mail.ru, mail sent add I receive it. Some ideas why?

Kalana Demel
  • 3,220
  • 3
  • 21
  • 34
Maksim Zarechnyi
  • 407
  • 3
  • 16
  • Have you tested sending an email out using `postfix` yet? – Samuel Toh Jan 30 '19 at 01:03
  • Yes, I added it to post - But if I use command `echo "First message" | mutt -s "msg" mymail@mail.ru`, mail sent add I receive it. – Maksim Zarechnyi Jan 30 '19 at 01:08
  • I think possibly something to do with your `postfix` configuration. Maybe research why the client is lossing its connection after sending the `EHLO` message. Not a `postfix` expert here, can't really help. – Samuel Toh Jan 30 '19 at 01:20

1 Answers1

2

If you followed similar set up for postfix as found here:

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

Then you should be able to get the following to run

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);
  }
});
Tim Mercer
  • 21
  • 3