gpt4 book ai didi

javascript - 在电子邮件正文中嵌入图像 nodemailer nodejs

转载 作者:IT老高 更新时间:2023-10-28 23:15:00 28 4
gpt4 key购买 nike

我正在遵循 nodemailer 社区中使用的方法 site但我似乎无法让它工作,因为我收到了错误

   Failed to send email { Error: ENOENT: no such file or directory, open 
'./rello-logo-full-svg.svg'
errno: -2,
code: 'ESTREAM',
syscall: 'open',
path: './rello-logo-full-svg.svg',
command: 'API' }

nodemailer选项如下

    let mailOptions = {
from: '<from_email>',
to: to_email_address.toString(),
subject: 'Subject',
text: 'Hello world', // plain text body
attachments: [{
filename: 'rello-logo-full-svg.svg',
path: './rello-logo-full-svg.svg',
cid: 'unique@cid'
}],
html: emailBody
};

emailBody 变量中,我有一个带有图像标签行的模板字符串,如下所示

<img style="width:250px;" cid:unique@cid>

我可能需要为 express 设置静态 Assets 还是什么,图像文件与具有上述代码的文件位于同一文件夹中,感谢任何帮助

最佳答案

在这里回复以防其他人遇到此问题!上面的 __dirname 确实很有帮助,但这是我实际查看嵌入在电子邮件中的图像的代码

我的img标签:

<img src="cid:logo">

我的附件片段:

attachments: [{
filename: 'Logo.png',
path: __dirname +'/folder/Logo.png',
cid: 'logo' //my mistake was putting "cid:logo@cid" here!
}]

关于javascript - 在电子邮件正文中嵌入图像 nodemailer nodejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48449379/

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