繁体   English   中英

如何使用 nodemailer 将图像附件作为 base64 发送?

[英]How to send image attachment as base64 with nodemailer?

我想使用 base64 发送带有附件的 email 但我无法使其工作并且没有显示错误,所有其他字段,例如“发件人”,“收件人”,“主题”和“文本”都可以,但是当我尝试发送附件时,仅在其他字段中收到 email。

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);
        }
    });
};

我用它 static 来查看它是否在没有从 input type="file" 上传的情况下发送,但它仍然无法正常工作,我想知道我能做些什么来发送带有 Z95A1446A7120E74AF5CZC887 字符串的 email。

附件。

没有附件选项。

使用复数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM