Rodrigo Leite
Rodrigo Leite

Reputation: 596

Emails with attachments come up empty using Nodemailer

I'm trying to send an e-mail with an attachment using Nodemailer. No matter what I do, if I specify an attachments property, the e-mail comes up empty (no attachments, no html, no text). Sending an e-mail without any attachments works as expected. Here's the code I have so far:

transporter.sendMail({
    to: `${toTitleCase(i.nome)} <${i.email}>`,
    subject: 'Treinamentos',
    text: 'hello!',
    html: `Embedded image: <img src="cid:[email protected]"/>`,
        attachments: [
            {
                filename: 'newimg.jpg',
                path: __dirname + '/src/img/newimg.jpg',
                cid: '[email protected]'
            }
        ]
    }, (err, info )=> {
        console.log(err);
        console.log(info);
    });

I have also tried using content instead of path, same result. I should also note that the err callback is empty.

Upvotes: 0

Views: 1420

Answers (1)

Rodrigo Leite
Rodrigo Leite

Reputation: 596

I figured it out. I had set 'Content-type': 'text/html; charset=UTF-8' as the header on the transporter object. Removing that line fixed the issue.

Upvotes: 0

Related Questions