Creating Mime message for message body and single attachment in nodemailer

302 Views Asked by At

I'm trying to create Mime message for message body and single html attachment in nodemailer using the raw property and its not delivering well. Sometimes it displays only base64 or the message body html but the attachment doesn't show well or renders the attachment and displays it below the html message body . Please note that i know there are properties there to use but i want to create mine using the raw property

const attachmentPath = './Attachment/index.html'
const oppoxHTML = '<html>hello World</html>'
raw:
    `Content-Type: text/html; charset=utf-8\r\n` +
    `Content-Transfer-Encoding: base64 \r\n` +  
    `From: "Joe Man" <[email protected]>\r\n`+
    `To: [email protected] \r\n`+
    `Subject: Test email with HTML attachment\r\n`+
    `MIME-Version: 1.0\r\n`+
    `Content-Type: multipart/mixed; boundary="--boundary"\r\n` +
    `Content-Type: text/html; charset=utf-8 \r\n`+
    `Content-Transfer-Encoding:base64 \r\n`+
    `${oppoxHTML} \r\n` +
    `\r\n`+
    `--boundary\r\n` +
    `Content-Type: text/html; charset=utf-8\r\n`+
    //`Content-Transfer-Encoding: base64\r\n`+
    `Content-Disposition: attachment; filename="attachment.html"\r\n`+

    `${fs.readFileSync(attachmentPath).toString('base64')}\r\n`+

    `---boundary--`
0

There are 0 best solutions below