Reputation: 407
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" <[email protected]>', // 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" [email protected]
, mail sent add I receive it.
Some ideas why?
Upvotes: 2
Views: 4256
Reputation: 31
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: '[email protected]', pass: 'yourlinuxuserpassword' },
tls: { rejectUnauthorized: false }
});
let mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'nodemailer test',
text: 'hope it got there'
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error);
} else {
console.log(info);
}
});
Upvotes: 3