DEV Community

ishwar
ishwar

Posted on

4

Sending Mail Using Nodejs, Configure via SMTP Port WebMail

/*
Nodemailer is a module for Node.js applications to allow easy as cake email sending. The project got started back in 2010 when there was no sane option to send email messages
*/

const nodemailer = require(‘nodemailer’);

/*
SMTP is the main transport in Nodemailer for delivering messages. SMTP is also the protocol used between different email hosts, so its truly universal. Almost every email delivery provider supports SMTP based sending
*/

var smtpTransport = require(‘nodemailer-smtp-transport’);

var transporter = nodemailer.createTransport(smtpTransport ({
tls: {
},
host: ‘’,
secureConnection: false,
port: 587,
auth: {
user: ‘’,
pass: ‘’
}
}));

var mailOptions = {
from: ‘’,
to: ‘’,
subject: ‘This is a test ‘,
text: ‘Hello this testing message’
};

transporter.sendMail(mailOptions, function(error, info){
console.log(“error,info”,error, info);
});

put in tls option rejectUnauthorized: false

/*
rejectUnauthorized: If true, the server certificate is verified against the list of supplied CAs. An error event is emitted if verification fails; err.code contains the OpenSSL error code. Default: true.
*/

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (1)

Collapse
 
maxwellcalkin profile image
Maxwell Calkin

hello! 4 years later, getting use out of your post. THANK YOU!
I'm having trouble with the "host" property. I'm trying to send emails from a WebMail address. What should I be putting as the value for "host"??

Thank you!

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs