3

在 Apps Script 中获取当前时间插入邮件正文

 2 years ago
source link: https://www.v2ex.com/t/818104
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Google

在 Apps Script 中获取当前时间插入邮件正文

  maogang39 · 17 小时 22 分钟前 · 146 次点击

https://developers.google.com/apps-script/reference/utilities/utilities#formatDate(Date,String,String) 中找到获取当前时间的方法

var formattedDate = Utilities.formatDate(new Date(), "GMT+8", "yyyy-MM-dd'T'HH:mm:ss'Z'"); Logger.log(formattedDate);

如何将获取到的时间插入到如下的邮件的正文中,可以让每封邮件的内容都不一致。

function fn() {

MailApp.sendEmail("1******.1*******[email protected].com", "", "Hello, World!");

MailApp.sendEmail("1******.1*******[email protected].com", "", "Hello, World!");

尝试过以下的方式,直接被 Google Apps Script 报错

function fn() {

var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");

Logger.log(formattedDate);

MailApp.sendEmail({"1******.1*******[email protected].com", "", "body: Logger.getLog(),Hello, World!"});

MailApp.sendEmail({"1******.1*******[email protected].com", "", "body: Logger.getLog(),Hello, World!"});


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK