Advertisement
Guest User

Wait for parse

a guest
Mar 31st, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let msg = {
  2.   to: TEAM_EMAILS,
  3.   from: 'BostonHacks <contact@bostonhacks.io>',
  4.   replyTo: req.body.from,
  5.   subject: req.body.subject,
  6.   text: req.body.text
  7. };
  8.  
  9. simpleParser(req.body.email, { skipImageLinks: true })
  10.   .then(parsed => {
  11.     UPDATE MSG WITH STUFF FROM PARSED
  12.     const msg = {
  13.       to: TEAM_EMAILS,
  14.       from: 'BostonHacks <contact@bostonhacks.io>',
  15.       replyTo: req.body.from,
  16.       subject: req.body.subject,
  17.       text: req.body.text,
  18.       ....
  19.     };
  20.   })
  21.   .catch(error => {
  22.     console.error("Failed to parse email:", error);
  23.     console.log("Sending email text as fallback");
  24.   });
  25.  
  26.   sgMail
  27.     .sendMultiple(msg)
  28.     .then(() => {
  29.       console.log('Email forwarded!');
  30.       res.send('Email forwarded!');
  31.     })
  32.     .catch(error => {
  33.       console.error('Email forwarding failed:', error.response.body);
  34.       res.status(500).send('Email forwarding failed!');
  35.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement