将图像嵌入到电子邮件正文中nodemailer nodejs [英] Embed image in email body nodemailer nodejs

查看:387
本文介绍了将图像嵌入到电子邮件正文中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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆