首页 > 解决方案 > 电子邮件模板/Nodemailer 电子邮件不包含模板

问题描述

我正在尝试发送一个 ejs 模板,email-templates但我并没有很高兴。

电子邮件发送正常,但不包含任何模板数据。

    const email = new Email ({
        template: 'activateAccount',
        message: {
            from: "noreply@domain.com",
            subject: "Activate your account!",
            to: data.email
        },
        locals: {
            name: data.name,
            url: data.url
        },
        send: true,
        transport: {
            host: "domain.com",
            port: 2525,
            auth: {
                user: "abc",
                pass: "123"
            }
        },
        views: {
            options: {
                extension: 'ejs'
            }
        }
    });

    return await email.send();

有谁知道为什么没有填充模板?

标签: node.jsnodemaileremail-templates

解决方案


使用localswhen.send发送电子邮件,

const email = new Email({
  message: {
    from: "noreply@domain.com",
    subject: "Activate your account!",
    to: data.email
  },
  send: true,
  transport: {
    host: "domain.com",
    port: 2525,
    auth: {
      user: "abc",
      pass: "123"
    }
  },
  views: {
    options: {
      extension: 'ejs'
    }
  }
});

await email.send({
  template: 'activateAccount',
  locals: {
    name: data.name,
    url: data.url
  }
});

基本上,您可以使用的所有选项都是.send函数本身。


推荐阅读