How to use nodemailer - 10 common examples

To help you get started, we’ve selected a few nodemailer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github voluntarily / vly2 / x / email / testemail.js View on Github external
})

  // send mail with defined transport object
  const info = await transporter.sendMail({
    from: '"Fred Foo 👻" ', // sender address
    to: 'bar@example.com, baz@example.com', // list of receivers
    subject: 'Hello ✔', // Subject line
    text: 'Hello world?', // plain text body
    html: '<b>Hello world?</b>' // html body
  })

  console.log('Message sent: %s', info.messageId)
  // Message sent: 

  // Preview only available when sending through an Ethereal account
  console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info))
  // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}
github jeremypeter / grunt-litmus / test / lib / test-litmus.js View on Github external
var request = require('request'),
    mail = require('nodemailer').mail,
    fs = require('fs'),
    cheerio = require('cheerio'),
    builder   = require('xmlbuilder'),
    Table = require('cli-table'),
    _ = require('lodash');


function Litmus(options){
  this.options = options;
  this.initVars();
}

// Initialize variables
Litmus.prototype.initVars = function() {

  this.reqObj = {
github schizobulia / warehouse / node / email.js View on Github external
});

    // send mail with defined transport object
    let info = await transporter.sendMail({
        from: '"Fred Foo 👻" ', // sender address
        to: '2833324528@qq.com', // list of receivers
        subject: 'Hello ✔', // Subject line
        text: 'Hello world?', // plain text body
        html: '<b>Hello world?</b>' // html body
    });

    console.log('Message sent: %s', info.messageId);
    // Message sent: 

    // Preview only available when sending through an Ethereal account
    console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
    // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}
github obiwankenoobi / react-express-boilerplate / server / src / services / activateAccountEmail.ts View on Github external
transporter.sendMail(mailOptions, (error, info) => {
        if (error) {
          console.log({ error });
          reject({
            error
          });
        }
        console.log("Message sent: %s", info.messageId);
        // Preview only available when sending through an Ethereal account
        console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
      });
      resolve({
github obiwankenoobi / react-express-boilerplate / server / src / services / resetPasswordEmail.ts View on Github external
transporter.sendMail(mailOptions, (error, info) => {
        if (error) {
          reject({
            message: "ERR",
            error
          });
        }
        console.log("Message sent: %s", info.messageId);
        // Preview only available when sending through an Ethereal account
        console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
      });
      resolve({
github obiwankenoobi / react-express-boilerplate / server / src / services / activateAccountEmail.ts View on Github external
return new Promise((resolve, reject) => {
    // Generate test SMTP service account from ethereal.email
    // Only needed if you don't have a real mail account for testing
    nodemailer.createTestAccount((err, mailAcc) => {
      // create reusable transporter object using the default SMTP transport
      const transporter = nodemailer.createTransport({
        host: process.env.smtp,
        port: 465,
        secure: true, // true for 465, false for other ports
        auth: {
          user: process.env.nodemailerEmail, // generated ethereal user
          pass: process.env.nodemailerPw // generated ethereal password
        }
      });
      console.log(process.env.nodemailerEmail, process.env.nodemailerPw);
      // setup email data with unicode symbols
      const mailOptions = {
        from: process.env.nodemailerEmail, // sender address
        to: email, // list of receivers
        subject: `thanks for signing up (: `, // Subject line
github amiklosi / Comicr / app.js View on Github external
require('./controllers/uploadFromWeb.js');
require('./controllers/uploadFromFlickr.js');
require('./controllers/facebook.js');
require('./controllers/sendEmail.js');
require('./controllers/imgur.js');
require('./controllers/formUpload.js');
require('./controllers/file.js');
require('./controllers/downloadImage.js');

app.listen(3000);

console.log('Comicr started on port 3000');

if (process.env.NODE_ENV != 'production') {
	console.log("Using gmail SMTP");
	nodemailer.SMTP = {
		host: "smtp.gmail.com", // required
		port: 465, // optional, defaults to 25 or 465
		use_authentication: true,
		ssl: true,
		user: "miklosi.attila@gmail.com",
		pass: "123bolombika"
	}
}
github anatoliychakkaev / railwayjs.com / node_modules / mailer / lib / mailer.js View on Github external
} catch (e) {
        console.log('Could not init mailer extension, env-specific settings not found in config/mailer.yml');
        console.log('Error:', e.message);
        return;
    }
    if (!settings) {
        return;
    }
    exports.settings = settings;

    switch (settings.mailer) {
    case 'sendmail':
        nodemailer.sendmail = true;
        break;
    case 'smtp':
        nodemailer.SMTP = {
            host: settings.host || "localhost",
            port: settings.port || 25,
            use_authentication: settings.use_authentication || false,
            user: settings.user || '',
            pass: settings.pass || ''
        };
        break;
    }

    // read app/views/emails dir
    var emailsDir = app.root + '/app/views/emails';
    if (path.existsSync(emailsDir)) {
        fs.readdirSync(emailsDir).forEach(function (file) {
            templates[file] = fs.readFileSync(emailsDir + '/' + file).toString('utf8');
        });
    }
github LockerProject / Locker / Apps / Reminisce / app.js View on Github external
request.get({uri:processInfo.lockerUrl+"/Me/photos/allPhotos"},function(err, res, body){
        if(err)
        {
            console.log("failed to get photos: "+err);
            return;
        }
        var photos = JSON.parse(body);
        // ideally this is a lot smarter, about weighting history, tracking to not do dups, etc
        var rand = Math.floor(Math.random() * photos.length);
        console.log("for "+auth.username+" we picked random photo: "+JSON.stringify(photos[rand]));
        // hard coded to gmail for testing (ver -0.1)
        nodemailer.SMTP = {
            host: 'smtp.gmail.com',
            port: 587,
            ssl: false,
            use_authentication: true,
            user: auth.username,
            pass: auth.password
        };
        // Message object
        var cid = Date.now() + '.image.png';
        var message = {
            sender: 'Reminisce &lt;42@awesome.com&gt;',
            to: auth.username,
            subject: 'something fun and random  ✔',
            body: 'Hello to myself!',
            html:'<p><b>reminiscing...</b> <img src="cid:"></p>',
            debug: true,
github nodeGame / nodegame / server / nodegame-server / ServerChannel.js View on Github external
function ServerChannel (options, server, io) {
	
	this.options = options;
	this.server = server;
	this.io = io;
		
	this.name = options.name;
	
	if (options.mail) {
		nodemailer.sendmail = true;
		nodemailer.send_mail({sender: this.name, 
	        				  to: options.mail.to,
					          subject: options.mail.subject,
					          body: "MAIL. For now you cannot change this..."}, // TODO allow for custom body
			    function(error, success){
	            console.log("Message "+(success?"sent":"failed"));
	        });
	}
	
	this.nPlayers = options.nPlayers;
	
	
	this.adminChannel = options.admin;
	this.playerChannel = options.player;
	
	this.port = options.port;