Kevin Kevin - 9 months ago 427
Node.js Question

Sending mail in node.js using nodemailer

I am trying to send mail in node.js using Nodemailer but it shows some error like

{ [Error: self signed certificate in certificate chain] code: 'ECONNECTION', command: 'CONN' }

My node.js code is

var express = require('express');
var app = express();
var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport('smtps://');

var mailOptions = {
to: '',
subject: 'Hello ?',
text: 'Hello world ??',
html: '<b>Hello world ??</b>'

transporter.sendMail(mailOptions, function(error, info){
return console.log(error);
console.log('Message sent: ' + info.response);

var server = app.listen(8900,function(){
console.log("We have started our server on port 8900");


To allow to send an email via “less secure apps”, go to the link and choose “Turn on”.

(More info about less secure apps)

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');

var mailAccountUser = '<YOUR_ACCOUNT_USER>'
var mailAccountPassword = '<YOUR_ACCOUNT_PASS>'

var fromEmailAddress = '<FROM_EMAIL>'
var toEmailAddress = 'TO_EMAIL'

var transport = nodemailer.createTransport(smtpTransport({
    service: 'gmail',
    auth: {
        user: mailAccountUser,
        pass: mailAccountPassword

var mail = {
    from: fromEmailAddress,
    to: toEmailAddress,
    subject: "hello world!",
    text: "Hello!",
    html: "<b>Hello!</b><p><a href=\"\">Click Here</a></p>"

transport.sendMail(mail, function(error, response){
        console.log("Message sent: " + response.message);