无法将图像附加到 pug html 和 nodemailer

时间:2021-03-03 02:38:36

标签: node.js automation pug attachment nodemailer

我们已经测试了很多方法,我很好奇我们是否需要向接口 EmailOptions 添加任何内容。发送电子邮件时,我们只能看到文件中的替代选项,但未呈现。

     interface EmailOptions<T = any> {
        /**
         * The template name
         */
        template?: string;
        /**
         * Nodemailer Message <Nodemailer.com/message/>
         *
         * Overrides what is given for constructor
         */
        message?: Mail.Options;
        /**
         * The Template Variables
         */
        locals?: T;
          ///do we need attachments?:someObj; here?
    }

这是图像文件的绝对路径。 包/api/image/header.jpg

这是邮件程序文件的绝对路径。 包/api/helper/mailer.js

This is the html.pug
img(src= 'header.jpg' alt='header' style='width:100%; height:auto;')

This is the email method
function sendSurveyEmail(application) {
  email.send({
    template: 'survey',
    message: {
      from: 'Person <person@email.org>',
      to: 'Other@person.io'
    },
    locals: {
      name: application.thisName,
      patientName: application.thatName,
      appUrl: process.env.APP_URL,
    },
    attachments: [{
      filename: 'header.jpg',
      path: '.public/image/header.jpg',
      cid: 'header.jpg' 
  }]
  }).catch((err) => console.log(err))
  .then(() => console.log('email has been sent!'));
}

0 个答案:

没有答案
相关问题