Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.email = function(req, res, options, tokens) {
- receiver_id= options.email.receiver_id;
- message= options.email.message;
- sender_email = options.email.sender_email;
- sender_name = options.email.sender_name;
- slug=options.info.slug;
- org_name=options.info.org_name;
- dir_url=options.info.dir_url;
- var https = require('https');
- str = '';
- //getting user email by id
- path = '/api/v1/people/' + receiver_id +'?__proto__=&access_token=' + tokens[slug];
- var options = {
- host: slug + '.nationbuilder.com',
- path: path,
- method: "GET",
- json: true,
- headers: {
- "content-type": "application/json",
- "accept": "application/json"
- },
- }
- var nb_req = https.get(options, req_callback);
- function req_callback(response, res) {
- response.on('data', function(chunk) {
- str += chunk;
- });
- response.on('end', function() {
- object = JSON.parse(str);
- receiver_email = object.person.email1;
- var nodemailer = require('nodemailer');
- var transporter = nodemailer.createTransport({
- port:465,
- host:"smtp.gmail.com",
- auth: {
- user: 'connect@alumninations.com', // Your email id
- pass: '69$6FK$b6PQu' // Your password
- }
- });
- var html = '<p>From: ' + sender_email + '<br>';
- html += 'To: ' + receiver_email + '</p>';
- html += "<p>"+message + "</p>"
- html += "<p>This message was delivered by the " + org_name + " alumni directory website, " + "<a href='" + dir_url
- + "'>" + dir_url + "</p>";
- var mailOptions = {
- from: 'connect@alumninations.com', // sender address
- to: 'petervankoughnett@gmail.com', // list of receivers
- subject: "A message from " + sender_name, // Subject line
- /*text: "Message sent to", // plaintext body*/
- html: html
- };
- transporter.sendMail(mailOptions, function(error, info){
- if(error){
- console.log(error);
- res.json({yo: 'error'});
- }else{
- console.log('Message sent: ' + info.response);
- res.sendStatus(200);
- };
- return res.sendStatus(200);
- });
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement