Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var fs = require('fs');
  2. var path = require('path');
  3. var lodash = require('lodash');
  4. var request = require('request');
  5.  
  6. var config = require(__basedir + '/config.json');
  7.  
  8. class MailGunMailAdapter {
  9.     constructor(domain, key, from) {
  10.         this.domain = domain;
  11.         this.key = key;
  12.         this.from = from;
  13.     }
  14.     rawMail(opts, callback){
  15.         request({
  16.             method: 'post',
  17.             url: 'https://api.mailgun.net/v3/'+this.domain+'/messages',
  18.             auth: {
  19.                 user: 'api',
  20.                 pass: this.key,
  21.             },
  22.             form: lodash.assign({from: this.from}, opts),
  23.             gzip: true,
  24.             json: true,
  25.         }, (err, res, data)=>{
  26.             if (err) return callback(err);
  27.             callback(null, data);
  28.         })
  29.     }
  30. }
  31.  
  32. if (!config.mailer) {
  33.     module.exports = {rawMail: function(opts, callback){callback(new Error("Mail not configured."))}};
  34. } else if (config.mailer.type == 'mailgun') {
  35.     module.exports = new MailGunMailAdapter(config.mailer.options.domain, config.mailer.options.key, config.mailer.from);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement