我正在尝试将pdf文件附加到邮件中。
这是过程:
1)从服务器获取文件
2)将其存储为变量
3)将变量附加到邮件附件的content属性
我以这段代码结尾:
// 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);
};
但是结果是一个空白文件,指定的PDF附件大小为〜45kb