Я пытаюсь прикрепить pdf-файл к почте.
Это процесс:
1) получить файл с сервера
2) storeэто как переменная
3) присоединить эту переменную к атрибуту содержимого почтового вложения
Я заканчиваю этим кодом:
// get the pdf file and return it
export const getInvoicePdf = async (cinema: string, erpCrendentials: ErpAccount, invoiceId: number) => {
try {
const response = await Axios.get(`https://cinema.cineoffice.fr/file.pdf`, {
headers: {
'DOLAPIENTITY': erpCrendentials.entity,
},
});
return response.data;
} catch (e) {
throw 'DOLIBARR_GET_INVOICE_BY_ID_ERROR';
}
};
// set the attachement and send the mail
export const sendOrderDeliveryEmail = async (cinemaCredentials: ICinemaCredential, mailer: nodemailer.Transporter, email: string, docs: CreateDeliveryPdf, order: IOrder, invoice: Buffer) => {
const mailOptions = {
from: {
address: process.env.MAIL_FROM_ADDRESS,
name: cinemaCredentials.cinema
},
to: email,
subject: 'subject',
html: '<html></html>',
attachments: [
{
filename: 'Facture.pdf',
content: invoice,
contentType: 'application/pdf'
}
]
};
const info = await mailer.sendMail(mailOptions);
};
Но результатпустой файл с указанным размером файла ~ 45 КБ в виде pdf-файла