Skip to content

Instantly share code, notes, and snippets.

@JaiParakh
Last active June 14, 2019 03:04
Show Gist options
  • Save JaiParakh/2c1dd7a40aab0acc166c6ba550a41697 to your computer and use it in GitHub Desktop.
Save JaiParakh/2c1dd7a40aab0acc166c6ba550a41697 to your computer and use it in GitHub Desktop.
makeBody(){
var arr = [];
for(var i=0;i<this.attachment.length;i++){
arr[i] = {
path: this.attachment[i],
encoding: 'base64'
}
}
//Mail Body is created.
if(this.attachment.length){
let mail = new mailComposer({
to: this.to,
text: this.body,
subject: this.sub,
textEncoding: "base64",
attachments: arr
});
}
else{
let mail = new mailComposer({
to: this.to,
text: this.body,
subject: this.sub,
textEncoding: "base64"
});
}
//Compiles and encodes the mail.
mail.compile().build((err, msg) => {
if (err){
return console.log('Error compiling email ' + error);
}
const encodedMessage = Buffer.from(msg)
.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/, '');
if(this.task === 'mail'){
this.sendMail(encodedMessage);
}
else{
this.saveDraft(encodedMessage);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment