Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. async function appendEmail(userId, from, to, subject, html) {
  2. const message =
  3. `From: ${from}\r\n
  4. To: ${to}\r\n
  5. Subject: ${subject}\r\n
  6. \r\n
  7. ${html}\r\n
  8. `;
  9. const currentUser = _.head(await SyncQuery.find(User, { id: userId }));
  10. const { imapEmail, imapPassword, imapServer } = currentUser;
  11. const imap = new IMAP({
  12. user: imapEmail,
  13. password: imapPassword,
  14. host: imapServer,
  15. port: 993,
  16. tls: true,
  17. });
  18. const options = {
  19. mailbox: 'Sent Items',
  20. };
  21.  
  22. imap.once('ready', () => {
  23. imap.append(message, options, (err) => {
  24. sails.log.error(new Error(err));
  25. imap.end();
  26. });
  27. });
  28.  
  29. imap.once('error', (err) => {
  30. sails.log.error(new Error(err));
  31. });
  32. imap.connect();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement