Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. makeBody(){
  2. var arr = [];
  3. for(var i=0;i<this.attachment.length;i++){
  4. arr[i] = {
  5. path: this.attachment[i],
  6. encoding: 'base64'
  7. }
  8. }
  9.  
  10. //Mail Body is created.
  11. if(this.attachment.length){
  12. let mail = new mailComposer({
  13. to: this.to,
  14. text: this.body,
  15. subject: this.sub,
  16. textEncoding: "base64",
  17. attachments: arr
  18. });
  19. }
  20. else{
  21. let mail = new mailComposer({
  22. to: this.to,
  23. text: this.body,
  24. subject: this.sub,
  25. textEncoding: "base64"
  26. });
  27. }
  28.  
  29. //Compiles and encodes the mail.
  30. mail.compile().build((err, msg) => {
  31. if (err){
  32. return console.log('Error compiling email ' + error);
  33. }
  34.  
  35. const encodedMessage = Buffer.from(msg)
  36. .toString('base64')
  37. .replace(/\+/g, '-')
  38. .replace(/\//g, '_')
  39. .replace(/=+$/, '');
  40.  
  41. if(this.task === 'mail'){
  42. this.sendMail(encodedMessage);
  43. }
  44. else{
  45. this.saveDraft(encodedMessage);
  46. }
  47. });
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement