I don't know which encoding to do while sending email attachment from postmark attachments feature in the Content field.
I have already tried the following method to convert the pdf file to base64 but not find working:
fs.readFileSync("./filename.pdf").toString('base64')
////////
pdf2base64("./filename.pdf").then(
(response) => {
base= response //cGF0aC90by9maWxlLmpwZw==
}
).catch(
(error) => {
console.log(error); //Exepection error....
}
)
/////
function base64_encode(file) {
// read binary data
var bitmap = fs.readFileSync(file);
// convert binary data to base64 encoded string
return new Buffer.from(bitmap.toString('utf-8'),'base64');
}
The code from which I am trying to send email is below:
var client = new postmark.ServerClient("*****");
client.sendEmail({
"From": "example@abc.com",
"To": "abc@abc.com",
"Subject": "Test",
"TextBody": "please find attached file of your agreement",
"Attachments": [
{
"Name": 'index.pdf',
"Content":fs.readFileSync("./filename.pdf").toString('base64'),
"ContentType": "application/pdf"
}
]
}).then((result) => {
console.log("the result is :", result)
}).catch((err) => {
console.log("error is : ", err)
});
All I want it to find the method of how to encode as per the requirement for this email attachment. What should I put in the content field to send the errorless file