在 base64 中发送更大的图像时 Nodemailer 崩溃

Nodemailer crashes when sending bigger image in base64

我想在电子邮件中嵌入二维码。这是我现在用来添加附件的代码:

mailOptions.attachments = [{
    filename: 'image.png',
    content: url.split("base64,")[1],
    encoding: 'base64'
}];

如果 url 等于:

"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgAQMAAADYVuV7AAAABlBMVEUAAAAAAAClZ7nPAAAAAXRSTlMAQObYZgAAAB9JREFUeAFjgIJRwP+BZM4oh/8/GHygIYd8h45yRgEAaHBnmaA4EHkAAAAASUVORK5CYII=";

但是,当我将其更改为二维码时:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHQAAAB0CAYAAABUmhYnAAAAAklEQVR4AewaftIAAAKsSURBVO3BQW7kQAwEwSxC//9yro88NSBIM2sTjIg/WGMUa5RijVKsUYo1SrFGKdYoxRqlWKMUa5RijVKsUYo1SrFGKdYoxRrl4qEkfJNKl4QTlS4JncpJEr5J5YlijVKsUYo1ysXLVN6UhDtUuiS8SeVNSXhTsUYp1ijFGuXiw5Jwh8oTSehUuiS8KQl3qHxSsUYp1ijFGuXij1M5ScJJEjqVv6xYoxRrlGKNcvHHJeFE5SQJkxRrlGKNUqxRLj5M5ZNU7kjCm1R+k2KNUqxRijXKxcuS8E1J6FS6JHQqXRLuSMJvVqxRijVKsUaJPxgkCZ1Kl4QTlb+sWKMUa5RijXLxUBI6lZMk/E8qXRK6JHQqJ0noVLok3KHyRLFGKdYoxRrl4j9TeSIJncoTKl0STlTuUPmkYo1SrFGKNcrFQypdEt6UhCeS0Kl0KneonCThjiR0Kk8Ua5RijVKsUeIPXpSEE5WTJHQqJ0l4QqVLQqdykoROpUvCicqbijVKsUYp1igXH6bSJeFEpUtCp9KpdEk4UXkiCSdJ6FS6JHxSsUYp1ijFGiX+4A9LQqdyRxI6lTuS0Kl0SbhD5YlijVKsUYo1ysVDSfgmlZMknKjckYQ7knCi8knFGqVYoxRrlIuXqbwpCU+odEk4ScI3JaFTeaJYoxRrlGKNcvFhSbhD5X9SOUlCp9IloVPpktCpvKlYoxRrlGKNcjGMSpeEE5UuCScqJyonKp9UrFGKNUqxRrn441S6JNyRhBOVkyR0Kl0S7lB5olijFGuUYo1y8WEq36TSJeEOlS4JnUqn8psUa5RijVKsUS5eloRvSkKn0qm8KQknKp3KNxVrlGKNUqxR4g/WGMUapVijFGuUYo1SrFGKNUqxRinWKMUapVijFGuUYo1SrFGKNUqxRvkHv7QE9MppxbsAAAAASUVORK5CYII=

代码很糟糕,出现以下错误:

Error: Connection closed
at SMTPConnection.<anonymous> (...\node_modules\nodemailer-smtp-transport\lib\smtp-transport.js:113:29)
...

我想是因为二维码比第一张图大,但是还是比较小。我尝试了很多方法,但都没有给我积极的结果。关于如何解决这个问题的任何想法?

如果您是从物理位置访问图像而不是使用此代码

var mailOptions = {
attachments: [{'filename': 'image.png','path': '\pathtoimagefile\image.png'}]

如果您从代码生成二维码而不是

    var qr_png = qr.imageSync('string', {
                    type: 'png'
                })
    var mailOptions = {
    attachments: [{'filename': 'image.png', 'content': qr_png}]

这段代码对我有用

注意:我正在使用'qr-image'将文本转换为二维码。