I'd like to send mails on my local server but it seems not working with Nodemailer and NodeJS.
Is there any solutions to send mails from local?
var contact = {subject: 'test', message: "test message", email: '[email protected]'};
var to = "[email protected]";
var transporter = nodemailer.createTransport();
transporter.sendMail({
from: contact.email,
to: to,
subject: contact.subject,
text: contact.message
});
Nodemailer works on local PC, but not on server.
Include the nodemailer module in the code using require('nodemailer'). Use nodemailer. createTransport() function to create a transporter who will send mail. It contains the service name and authentication details (user ans password).
For more details, refer to the Nodemailer documentation. With SMTP, everything is pretty straightforward. Set host, port, authentication details and method, and that's it. It's also useful to verify that SMTP connection is correct at this stage: add verify(callback) call to test connection and authentication.
In this tutorial, we'll cover how to configure an email address for Nodemailer, send emails from inside of an application, attach files to an email, add fields for CC and BCC, and finally, add CSS and HTML styling to an email template.
const transporter = nodemailer.createTransport({
port: 25, // Postfix uses port 25
host: 'localhost',
tls: {
rejectUnauthorized: false
},
});
var message = {
from: '[email protected]',
to: '[email protected]',
subject: 'Confirm Email',
text: 'Please confirm your email',
html: '<p>Please confirm your email</p>'
};
transporter.sendMail(message, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
});
I'm current triggering this through an restful API on express.js. This should work, I used this to set up my postfix on digitalocean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With