How to use emailjs - 10 common examples

To help you get started, we’ve selected a few emailjs 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 jupe / home.js / app / services / cron.js View on Github external
function sendEmail( to, subject, msg, cb){
    var cfg = CFG.email;
    var server  = email.server.connect( cfg );
    server.send( {
        text: msg, from: cfg.from, to: to, subject: subject
      }, function (err, message) {
        if (err) {
          // handle error
          console.log('There was an error sending the email');
          console.log(err);
          event('error', 'sendEmail failed',  err);
          if(cb)cb(err);
        }else {
            console.log('Email sended');
            console.log(message);
            event('info', 'sendEmail', message);
          if(cb)cb(null, message);
        }
      });
github PacktPublishing / Industrial-Internet-Application-Development / Chapter06 / timeseries / alert-email.js View on Github external
var email = require('emailjs');

var server = email.server.connect({
  user: 'username@gmail.com',
  password: 'password',
  host: 'smtp.gmail.com',
  ssl: true
});

// send the message and get a callback with an error or details of the message that was sent
function alertEmail(msg) {
  server.send({
    text: msg,
    from: 'username@gmail.com',
    to: 'username@gmail.com',
    subject: 'Alert'
  }, function (err, message) {
    console.log(err || message);
  });
github FlowzPlatform / workflow / service / src / services / sendmail / sendmail.class.js View on Github external
//  console.log(params)
  let smtpUser = user
  let smtpPassword = password
  let smtpHost = host
  if (params.headers.smtp_user) {
    smtpUser = params.headers.smtp_user
  }
  if (params.headers.smtp_password) {
    smtpPassword = params.headers.smtp_password
  }
  if (params.headers.smtp_host) {
    smtpHost = params.headers.smtp_host
  }
  // console.log('', smtpHost, smtpPassword, smtpUser)
  if (smtpHost !== '' && smtpHost !== undefined && smtpPassword !== '' && smtpPassword !== undefined && smtpHost !== '' && smtpHost !== undefined) {
    let SMTPServer = email.server.connect({
      user: smtpUser,
      password: smtpPassword,
      host: smtpHost,
      ssl: false
    });
    return new Promise((resolve, reject) => {
      SMTPServer.send({
        text: data['body'],
        // html: 'Nikita',
        from: data['from'],
        to: data['to'],
        cc: data['cc'],
        bcc: data['bcc'],
        subject: data['subject'],
        attachment: 
         [
github cn007b / my / ed / nodeJs / _ruBookPauersS / pdfToServer / pdf.node.js View on Github external
console.log('sending email');
                    // отправка сообщения по электронной почте
                    var server = emailjs.server.connect({
                        user : 'gmail.account.name',
                        password : 'gmail.account.passwod',
                        host : 'smtp.gmail.com',
                        port : 587,
                        tls : true
                    });
                    var headers = {
                        text : 'You can find your split PDF at ' + url,
                        from : 'youremail',
                        to : email,
                        subject: 'split pdf'
                    };
                    var message = emailjs.message.create(headers);
                    message.attach({
                        data:"<p>You can find your split PDF at " + "<a href="&quot; + url + &quot;">" + url + "</a></p>",
                        alternative: true
                    });
                    server.send(message, function(err, message) {
                        console.log(err || message);
                    });
                    pdftk.kill();
                });
                pdftk.stderr.on('data', function (data) {
github stimulant / ampm / node_modules / winston-mail / lib / winston-mail.js View on Github external
if (meta !== null && meta !== undefined && (typeof meta !== 'object' || Object.keys(meta).length > 0))
      body += "\n\n" + util.inspect(meta, {depth: 5}); // add some pretty printing

  var msgOptions = {
    from: this.from,
    to: this.to,
    subject: this.subject({level: level, msg: msg.split('\n')[0]}),
    text: body
  };

  //Send mail as html
  if (this.html){
    msgOptions.attachment = [{data: body , alternative:true}];
  }
  
  var message = email.message.create(msgOptions);
  
  this.server.send(message, function (err) {
    if (err) self.emit('error', err);
    self.emit('logged');
    callback(null, true);
  });
};
github educatopia / educatopia / api / email-dispatcher.js View on Github external
// ---- module dependencies --------------------- 
var EM = {}
module.exports = EM

// ---- module attributes -----------------------
var mailsettings = {
	host 	 : '',
	user 	 : '',
	password : '',
    sender   : '',
    ssl      : true
}

EM.server = require("emailjs/email").server.connect({
	host 	 : mailsettings.host,
	user 	 : mailsettings.user,
	password : mailsettings.password
    //ssl      : mail.ssl
})

// ---- module exports --------------------------
EM.dispatchRegistrationMail = function(account, callback) {
    var text = "welcome to educatopia\n" +
               "please click the link below!" +
               "http://educatopia.org/verify?user=" + account._id;

	EM.server.send({
		from         : mailsettings.sender,
		to           : account.email,
		subject      : 'educatopia registration',
github xenophy / NextJS / lib / nx / app / action / Abstract / dollar_mail.js View on Github external
charset: 'iso-2022-jp',
        header: {
            'message-id': '&lt;' + (new Date()).getTime() + '.' + process.pid + '@' + NX.Os.hostname() + '&gt;'
        }
    });

    NX.applyIf(config, {
        content: 'text/plain; charset=' + config.charset.toLowerCase()
    });

    var iconv = new Iconv('UTF-8', config.charset);

    var buffer = iconv.convert(config.subject || '');
    config.subject = buffer.toString();

    var message = email.message.create(config);

    // 添付ファイル処理
    if(config.files) {

        if(NX.isObject(config.files)) {
            config.files = [config.files];
        }

        if(NX.isArray(config.files)) {

            config.files.forEach(function(item) {

                var name = item.name;
                var ext = name.substr(name.indexOf('.') + 1);

                if(!item.type) {
github nickbalestra / zero / __tests__ / email.js View on Github external
test('deliver.send()', async () => {
  const deliver = email(smtpConfig);

  const token = '123.123.123';
  const user = { name: 'John', email: 'john@doe.com' };
  const req = { hostname: 'a-domain.com', protocol: 'http' };
  await deliver.send(user, token, req);

  expect(emailjs.__spy.connect).toHaveBeenCalledWith({
    host: 'smtp.domain.com',
    password: 'secure',
    port: '465',
    ssl: true,
    user: 'user@domain.com'
  });
  expect(emailjs.__spy.send.mock.calls[0][0]).toEqual({
    from: 'from@domain.com',
    subject: 'Token for a-domain.com!',
    text:
      'Hello!\nAccess your account here: http://a-domain.com/?token=123.123.123',
    to: 'john@doe.com'
  });
});
github nickbalestra / zero / __tests__ / email.js View on Github external
...smtpConfig
  });

  const token = '123.123.123';
  const user = { name: 'John', email: 'john@doe.com' };
  const req = { hostname: 'a-domain.com', protocol: 'http' };
  await deliver.send(user, token, req);

  expect(emailjs.__spy.connect).toHaveBeenCalledWith({
    host: 'smtp.domain.com',
    password: 'secure',
    port: '465',
    ssl: true,
    user: 'user@domain.com'
  });
  expect(emailjs.__spy.send.mock.calls[0][0]).toEqual({
    from: 'from@domain.com',
    subject: 'Token for a-domain.com!',
    text:
      'Hello!\nAccess your account here: http://a-domain.com/?acceptToken=123.123.123',
    to: 'john@doe.com'
  });
  expect(deliver.tokenField).toBe('acceptToken');
});
github developmentseed / jekyll-hook / jekyll-hook.js View on Github external
#!/usr/bin/env node

var config  = require('./config.json');
var fs      = require('fs');
var express = require('express');
var app     = express();
var queue   = require('queue-async');
var tasks   = queue(1);
var spawn   = require('child_process').spawn;
var email   = require('emailjs/email');
var mailer  = email.server.connect(config.email);
var crypto  = require('crypto');

app.use(express.bodyParser({
    verify: function(req,res,buffer){
        if(!req.headers['x-hub-signature']){
            return;
        }

        if(!config.secret || config.secret==""){
            console.log("Recieved a X-Hub-Signature header, but cannot validate as no secret is configured");
            return;
        }

        var hmac         = crypto.createHmac('sha1', config.secret);
        var recieved_sig = req.headers['x-hub-signature'].split('=')[1];
        var computed_sig = hmac.update(buffer).digest('hex');

emailjs

send text/html emails and attachments (files, streams and strings) from node.js to any smtp server

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis