gpt4 book ai didi

node.js - 如何使用nodemailer在Node.js中将base64字符串作为图像发送?

转载 作者:太空宇宙 更新时间:2023-11-04 00:10:25 24 4
gpt4 key购买 nike

我有nodejs get请求,需要将base 64字符串作为电子邮件中的图像发送,如下所示

router.post('/sendEmailNotification', function(req, res, next){
var inlineBase64 = require('nodemailer-plugin-inline-base64');
//here i have big image
let img ='/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBx'
var transporter = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
port: 587,
secure: false,
// secure: true,
secureConnection: false,// true for 465, false for other ports
auth: {
user: 'dhanalakshmi.07k@gmail.com',
pass: '23'
},
tls:{
rejectUnauthorized:false
}
});
transporter.use('compile', inlineBase64({cidPrefix: 'somePrefix_'}));
var mailOptions = {
from: 'dhanalakshmi.06k@gmail.com',
to: 'dhanalakshmi.06k@gmail.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!',

html: '<img src=data:image/png;base64,'+img+'/>'
};

transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
res.send(info.response);
}
});

});

电子邮件发送后,应该以图像形式收到,但它显示带有图像字符串的整个标签,请说

html: '<img src=data:image/png;base64,'+img+'/>' how should i send this to get the actual image 

最佳答案

像这样使用它:

html: '<html><body><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA9QAAADmCAIAAAC77FroAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAO..."></body></html>'

关于node.js - 如何使用nodemailer在Node.js中将base64字符串作为图像发送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49923953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com