How to attach file to an email with nodemailer

前端 未结 8 2129
南笙
南笙 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:34

    Your code is almost right, just need to add, "attachments" property for attaching the files in your mail,

    YOUR mailOption:

    var mailOption = {
            from: from,
            to:  to,
            subject: subject,
            text: text,
            html: html
    }
    

    Just add attachments like

    var mailOption = {
            from: from,
            to:  to,
            subject: subject,
            text: text,
            html: html,
            attachments: [{
                filename: change with filename,
                path: change with file path
            }]
    }
    

    attachments also provide some other way to attach file for more information check nodemailer community's documentation HERE

提交回复
热议问题