Advertisement
Guest User

Untitled

a guest
Jun 15th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. var nodemailer=require('nodemailer');
  2. var sgTransporter = require('nodemailer-sendgrid-transport');
  3. var options={
  4. auth: {
  5. api_user: "xxx",
  6. api_pass: "xxx"
  7. }
  8. };
  9. var client = nodemailer.createTransport(sgTransporter(options));
  10.  
  11. var sendMail=function(emailTo, subject, html, fn){
  12. var mailOptions={
  13. from:'xxx',
  14. to:emailTo,
  15. subject:subject,
  16. html:html
  17. };
  18.  
  19. client.sendMail(mailOptions, function(error, response){
  20. if(error){
  21. console.log(error);
  22. fn(error);
  23. }
  24. else{
  25. console.log("Message sent: " + response.message);
  26. fn(response);
  27. }
  28. });
  29. };
  30.  
  31. router.get('/verifyEmail', function(req,res){
  32. if(req.isAuthenticated()) {
  33. var subject='Verify your email address';
  34. var link="https://grovemonitor-jamesokbo.c9users.io/verify/:"+req.user._id;
  35. var html='Hello,<br> Please Click on the link to verify your Account.<br><a href='+link+'>Click here to verify</a>';
  36. console.log('Sending verification email to: '+req.user.email);
  37. sendMail(req.user.email,subject, html,function(error, response){
  38. if (error){
  39. return res.status(400).json({error:error});
  40. }
  41. return res.status(200).json(response);
  42. });
  43. }
  44. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement