将图像嵌入到电子邮件正文中nodemailer nodejs

编程入门 行业动态 更新时间:2024-10-28 00:20:58
本文介绍了将图像嵌入到电子邮件正文中nodemailer nodejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在遵循nodemailer社区站点中使用的方法. 但由于出现错误,我似乎无法使其正常工作

I am following the approach used in the nodemailer community site but I cannot seem to get it to work as I am getting the error

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选项如下

The nodemailer options are as follows

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 变量中,我有一个模板字符串,带有像这样的图像标签行

And in the emailBody variable I have a template string with an image tag line like so

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

我可能需要设置静态资产来表示还是什么,图像文件与具有上述代码的文件位于同一文件夹中,因此可以提供任何帮助

Do I maybe need to set the static assets for express or what, the image file is in the same folder as the file that has the above code, any help is appreciated

推荐答案

所以我通过使用 ...

So I got it to work by using ...

path: __dirname + '/rello-logo-full-svg.svg',

....

但是有趣的是,这并不是我想要达到的目的,因为我希望图像可以显示在电子邮件正文中,但希望这会对其他人有所帮助.

But funny this is not what I was trying to achieve because I wanted the image to be in the email body, bu hope this'll help someone else.

嘿,我刚刚将文件名从 .svg 更改为 .png ,我犯的另一个错误是模板中的图片,我将其更改为

Hey, I just changed the file name from .svg to .png, another mistake I made was with the image in the template, I have changed it to

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

更多推荐

将图像嵌入到电子邮件正文中nodemailer nodejs

本文发布于:2023-11-09 03:05:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571223.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文中   图像   电子邮件   nodejs   nodemailer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!