0

I'm using nodemailer and I'm trying to get my promotion emails annotated and highlighted in the Gmail promotions tab.

Here's the example:

'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: 'dummyuser@gmail.com',
      pass: 'dummypass'
    }
  });
  
  await transporter.sendMail({
    from: 'dummyuser@gmail.com',
    to: 'dummypromotabtesting@gmail.com',
    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);

And the template of the mail imported from 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!!!

Looking at the mail source from the gmail inbox, everything seems fine. The source is Quoted-Printable encoded (which shouldn't be a problem) and after decoding it, it passes the schema validation. Looking at the official documentation, the dates should be in ISO 8601 format like 2023-10-25T18:44:37-07:00 which .toISOString() doesn't produce. After sending dates as 2023-03-25T00:00:00+01:00 (ends) the email gets correctly annotated and highlighted. Is there any option other than parsing the date manually or adding a moment.js-like package just for that simple date conversion?

0 Answers0