Felipe Freire
Felipe Freire

Reputation: 51

How to send image attachment as base64 with nodemailer?

I want to send an email with an attachment using base64 but i can't make it to work and no error's are shown, all other fields such as "from", "to", "subject" and "text" are ok, but when i try to send an attachment the email is received only with the other fields.

const transporter = nodemailer.createTransport(mailGun(auth));

const sendMail = (email, subject, text, cb) => {
    const mailOptions = {
        from: email,
        to: myEmail,
        subject: subject,
        html: text,
        attachment: [
            {
                filename: "teste.png",
                content:
                    "iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAIAAAC0tAIdAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYSURBVChTY/hPChhVjQlGVWMC2qn+/x8AVR2gfKxsc/UAAAAASUVORK5CYII=",
                encoding: "base64",
            },
        ],
    };

    transporter.sendMail(mailOptions, (err, data) => {
        if (err) {
            cb(err, null);
        } else {
            cb(null, data);
        }
    });
};

I used it static to see if it was sending without uploading from input type="file" and it's still not working, i'd like to know what i can do to send an email with base64 string.

Upvotes: 2

Views: 1410

Answers (1)

Abraham Labkovsky
Abraham Labkovsky

Reputation: 1956

attachments.

There is no attachment option.

Use the plural.

Upvotes: 1

Related Questions