Gmail 促销选项卡中带注释的电子邮件不支持 .toISOString() 格式的日期

问题描述 投票:0回答:0

我正在使用 nodemailer,我正在尝试让我的促销电子邮件在 Gmail 促销选项卡中注释和突出显示。

举个例子:

'use strict';
const nodemailer = require('nodemailer');
const pug = require('pug');

async function main() {
  const transporter = nodemailer.createTransport({
    name: 'dummyName',
    pool: true,
    service: 'gmail',
    auth: {
      user: '[email protected]',
      pass: 'dummypass'
    }
  });
  
  await transporter.sendMail({
    from: '[email protected]',
    to: '[email protected]',
    subject: 'Promo test',
    html: pug.compileFile('./mail.pug', )({
      starts: new Date('2023-02-25').toISOString(),
      ends: new Date('2023-03-25').toISOString()
    })
  });

  transporter.close();
}

main().catch(console.error);

以及从

mail.pug
导入的邮件模板:

doctype html
html(lang='en')
  head
    title Dummy discount
    script(type='application/ld+json')
      | [{
      |   "@context": "http://schema.org/",
      |   "@type": "DiscountOffer",
      |   "description": "10% off",
      |   "discountCode": "DUMMY_CODE",
      |   "availabilityStarts": "#{starts}",
      |   "availabilityEnds": "#{ends}"
      | }]
  body
    p Hey, you have a 10% discount!!!

从gmail收件箱查看邮件来源,一切似乎都很好。源代码是 Quoted-Printable 编码的(这应该不是问题),解码后,它通过了schema validation。查看official documentation,日期应该采用ISO 8601格式,如

2023-10-25T18:44:37-07:00
,而
.toISOString()
不会产生。 将日期发送为
2023-03-25T00:00:00+01:00
(结束)后,电子邮件会得到正确的注释和突出显示。除了手动解析日期或为简单的日期转换添加类似 moment.js 的包之外,还有其他选择吗?

node.js pug nodemailer json-ld gmail-promo-tab
© www.soinside.com 2019 - 2024. All rights reserved.