如何匹配日期的时区:从 Google Apps 脚本发送的电子邮件的 header 与执行用户的时区?

How can I match the time zone of the Date: header of emails sent from Google Apps script to the time zone of the executing user?

我正在尝试从 Google Apps 脚本发送电子邮件。
我正在使用下面的示例,但日期的时区:发送电子邮件的 header 与执行用户的时区不同。

function sendEmailTest() {
  var to = "test@example.com";
  var subject = "Test";
  var timeZone = Session.getScriptTimeZone();
  var message = Utilities.formatDate(new Date(), timeZone, "yyyy/MM/dd HH:mm:ss");
  GmailApp.sendEmail(to,subject,message);
}

从该脚本发送的电子邮件如下。

From:     example@gmail.com
To:       test@example.com
Subject:  Test
Date:     Fri, 9 Oct 2020 16:51:01 -0700

2020/10/10 08:51:01

消息body中执行用户日期的时区是UTC+09:00,但是邮件的Date:header的时区是UTC-07: 00.

如何匹配日期的时区:从 Google Apps 脚本发送的电子邮件的 header 与执行用户的时区?

RFC5322 Internet Message Format - 3.6.1 The Origination Date Field 描述:

In any case, it is specifically not intended to convey the time that the message is actually transported, but rather the time at which the human or other creator of the message has put the message into its final form, ready for transport.

从 Google Apps 脚本发送的电子邮件的 Date header 的时区由服务器 运行 脚本指定。

因此我无法将日期header的时区修改为执行用户的时区。

但是收件人的客户端可能会以他们本地的格式和时区显示时间,所以我不必担心。

似乎无法从 gmail api 或应用脚本中的 GmailApp 修改日期字段的时区。它“似乎”基于 api 连接的服务器,这可能是随机的。但是,通过 MailApp 的时区发送的电子邮件固定为 00:00 UTC。在测试期间看到以下“原始”Date: <date> 结果。请注意,客户端可以使用任何选定的语言或时区来显示时区。下面仅记录使用“显示原始”显示的原始 Date 字段:

  • 直接从用户界面发送的电子邮件:

    • 您当前浏览器时区的时区偏移量。
  • 使用 MailApp 发送的电子邮件:

    • 时区偏移固定为 0000。没有抵消。未显示时区偏移数据。
  • 使用GmailApp发送的电子邮件:

    • 时区偏移量 fixed-probably 随机或当前接受您请求的服务器的时区。(比如 -0600)。
  • 使用 GmailAPI 使用 Google API 浏览器发送的电子邮件:

    • 时区偏移量 fixed-probably 随机或当前接受您请求的服务器的时区。(比如 -0600)。

时区偏移量没有随着

而改变
  • IP 地址
  • Language/location 更改为 Google settings
  • 在文件 > 项目属性 > 时区中看到的脚本项目的时区
  • Date 在 gmail 的“原始”参数中设置的字段 api 请求正文