I send the attachment in the base64 format, set a content type and a size properly, I also see the attachment in the email with the correct name and size, but when try to open it got “Couldn’t preview file. There was a problem displaying this image”. Also try to download and open, but got the error “Can’t open the file”. The size and format are correct. Tried with png and pdf with gmail emails. But I need pdf for this specific case.
here is how i convert the file to base64:
const response = await fetch(purchaseRequest.fileItem.attachedFile.url);
if (!response.ok) {
throw new Error(
Failed to fetch file from ${purchaseRequest.fileItem.attachedFile.url}
,
);
}
const fileBuffer = await response.buffer();
const base64Content = fileBuffer.toString(‘base64’);
await nylasService.sendEmail(connection.id, {
to: [
{
email: purchaseRequest.orderId.company.email,
},
],
from: [
{
email: ctx.state.user.email,
},
],
subject,
body,
attachments: [
{
content: base64Content,
content_type: purchaseRequest.fileItem.attachedFile,
filename: ${purchaseRequest.fileItem.attachedFile.hash}.pdf
,
id: purchaseRequest.fileItem.attachedFile.id,
is_inline: false,
size: purchaseRequest.fileItem.attachedFile.size,
},
],
});
The email body and subject are correct. Thanks you in advance!