How to attach file to an email with nodemailer

前端 未结 8 2125
南笙
南笙 2020-12-04 19:49

I have code that send email with nodemailer in nodejs but I want to attach file to an email but I can\'t find way to do that I search on ne

8条回答
  •  甜味超标
    2020-12-04 20:23

    Just look at here. Nodemailer > Message configuration > Attachments

    The code snippet is below (pdfkit gets the stream):

    // in async func
    pdf.end();
    const stream = pdf;
    const attachments = [{ filename: 'fromFile.pdf', path: './output.pdf', 
    contentType: 'application/pdf' }, { filename: 'fromStream.pdf', content: stream, contentType: 'application/pdf' }];
    await sendMail('"Sender" ', 'reciver@test.com', 'Test Send Files', '

    Hello

    ', attachments);

    Stream uses content not streamSource This bothered me before, share with everyone :)

提交回复
热议问题