3

I read the following, Sending emails in Node.js? but I'm looking for a way to send an email, not through an smtp server. As in the linux envirement you have different options such as sendmail and others

I could ofc use the environment I'm in to make use of the already existing functionality, but I would be interested to learn how one would dispatch the email using only js, if even possible..


I set up an smtp server using the smtp module: https://github.com/andris9/smtp-server why I'm interested in the delivery part of a server I already setup.

Community
  • 1
  • 1
superhero
  • 6,281
  • 11
  • 59
  • 91

4 Answers4

4

Take a look at node-mailer. You can set it up without smtp server. https://github.com/nodemailer/nodemailer

user1695032
  • 1,112
  • 6
  • 10
  • IIRC this is the minimum transport config `var transporter = nodemailer.createTransport('direct:?name=hostname');` Take the first example from the docs and replace the transport config with this and it should work – user1695032 Sep 12 '16 at 11:51
  • ...which is using this module to deliver the email: https://github.com/nodemailer/nodemailer-direct-transport – superhero Sep 28 '16 at 15:42
1

First:Install nodemailer
npm install nodemailer
Then put this into your node file:

var nodemailer = require('nodemailer');
var http = require('http');
var url = require('url');
console.log("Creating Transport")
var transporter = nodemailer.createTransport({
    service:'Hotmail',
    auth: {
        user:'salace2008765@outlook.com',
        pass: 'alice123@'
   }
});
var mailOptions = {
    from:'salace2008765@outlook.com',
    to: 'jerome20090101@gmail.com',
    subject: 'This is a test: test',
    text:'TgK'
}
console.log("Sending mail")
transporter.sendMail(mailOptions, function(error, info) {
    if (error) {
        console.log(error);
    } else {
        console.log('Email sent: ' + info.response)
    }
})

It usally works Sources:W3Schools and Nodemailer's official site

coder
  • 55
  • 7
0
     var nodemailer = require('nodemailer');
     var send = require('gmail-send');
     var mailserverifo = nodemailer.createTransport({
     service: 'gmail',
     host : "smtp.gmail.com",
     port : "465",
     ssl : true,
     auth: {
     user: 'email@gmail.com',
     pass: 'password@'
    }
    });
      var Mailinfo = {
      from: 'email@gmail.com',
      to: 'email@info.com',
      subject: 'Testing email from node js server',
      text: 'That was easy!'
     };

    mailserverifo.sendMail(Mailinfo, function(error, info){
    if (error) {
     console.log(error);
    } else {
     console.log('Email Send Success: ' + info.response);
    }
    });

   Enable less secure app form setting -
   https://www.google.com/settings/security/lesssecureapps
   Disable Captcha  - 
   https://accounts.google.com/b/0/displayunlockcaptcha
Siddharth Shukla
  • 1,063
  • 15
  • 14
0

You can use sendmail in Node js. I'v using it and it's working fine for me.

npm install sendmail --save

const sendmail = require('sendmail')();
 
sendmail({
    from: 'no-reply@yourdomain.com',
    to: 'test@qq.com, test@sohu.com, test@163.com ',
    subject: 'test sendmail',
    html: 'Mail of test sendmail ',
  }, function(err, reply) {
    console.log(err && err.stack);
});

https://www.npmjs.com/package/sendmail

GameBoy
  • 111
  • 7