用户 Gmail 账号中的邮件。
方法
| 方法 | 返回类型 | 简介 |
|---|---|---|
create | Gmail | 使用回复地址创建回复此邮件发件人的邮件草稿。 |
create | Gmail | 使用“回复”地址创建一封回复此邮件发件人的草稿邮件,并带有可选实参。 |
create | Gmail | 创建一封草稿邮件,使用“回复”地址和相应邮件的所有收件人回复发件人。 |
create | Gmail | 使用“回复”地址和所有收件人创建一封草稿邮件,以回复相应邮件的发送者,并可使用可选实参。 |
forward(recipient) | Gmail | 将此邮件转发给新的收件人。 |
forward(recipient, options) | Gmail | 将此消息转发给新收件人,并带有可选实参。 |
get | Gmail | 获取相应消息的所有附件。 |
get | Gmail | 获取相应消息的所有附件。 |
get | String | 获取此消息中以逗号分隔的密送收件人。 |
get | String | 获取相应邮件正文的 HTML 内容。 |
get | String | 获取此消息中以逗号分隔的抄送收件人。 |
get | Date | 获取相应消息的日期和时间。 |
get | String | 获取该邮件的发件人。 |
get | String | 根据标头名称获取 RFC 2822 标头的值。 |
get | String | 获取相应消息的 ID。 |
get | String | 获取相应邮件正文的内容(不含 HTML 格式)。 |
get | String | 获取相应消息的原始内容。 |
get | String | 获取相应邮件的回复地址(通常为发件人)。 |
get | String | 获取该邮件的主题。 |
get | Gmail | 获取包含相应消息的线程。 |
get | String | 获取相应消息的收件人(以逗号分隔)。 |
is | Boolean | 获取相应消息是否为草稿。 |
is | Boolean | 获取相应消息是否为聊天消息。 |
is | Boolean | 获取相应消息是否位于收件箱中。 |
is | Boolean | 如果相应邮件位于“优先收件箱”中,则返回 true;否则返回 false。 |
is | Boolean | 获取相应消息是否位于“已删除邮件”文件夹中。 |
is | Boolean | 获取相应消息是否已加星标。 |
is | Boolean | 获取相应消息是否未读。 |
mark | Gmail | 将邮件标记为已读。 |
mark | Gmail | 将邮件标记为未读。 |
move | Gmail | 将邮件移至回收站。 |
refresh() | Gmail | 从 Gmail 重新加载此消息和关联状态(如果标签、已读状态等发生更改,此方法非常有用)。 |
reply(body) | Gmail | 使用回复地址回复此邮件的发件人。 |
reply(body, options) | Gmail | 使用回复地址回复此邮件的发件人,并带有可选实参。 |
reply | Gmail | 回复发件人(使用回复地址)以及此邮件的所有收件人。 |
reply | Gmail | 使用回复地址和所有收件人回复此邮件的发送者,并带有可选实参。 |
star() | Gmail | 为消息添加星标。 |
unstar() | Gmail | 为消息移除星标。 |
详细文档
createDraftReply(body)
使用回复地址创建一封回复相应邮件发件人的邮件草稿。电子邮件的大小(包括标题)超出配额限制。
// Create a draft reply to the original message with an acknowledgment. const firstThread = GmailApp.getInboxThreads(0, 1)[0]; const message = firstThread.getMessages()[0]; message.createDraftReply('Got your message');
参数
| 名称 | 类型 | 说明 |
|---|---|---|
body | String | 电子邮件的正文。 |
返回
GmailDraft - 新创建的草稿消息。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
createDraftReply(body, options)
使用“回复”地址创建一封回复此邮件发件人的草稿邮件,并带有可选实参。
电子邮件可以同时包含纯文本和 HTML 正文。电子邮件的大小(包括标题)受配额限制。
// Create a draft response with an HTML text body. const firstThread = GmailApp.getInboxThreads(0, 1)[0]; const message = firstThread.getMessages()[0]; message.createDraftReply('incapable of HTML', { htmlBody: '<b>some HTML body text</b>', cc: 'another@example.com', });
参数
| 名称 | 类型 | 说明 |
|---|---|---|
body | String | 电子邮件的正文。 |
options | Object | 一个 JavaScript 对象,用于指定高级参数,如下所列。 |
高级参数
| 名称 | 类型 | 说明 |
|---|---|---|
attachments | Blob | 要随电子邮件一起发送的文件数组 |
bcc | String | 以逗号分隔的密送电子邮件地址列表 |
cc | String | 以逗号分隔的抄送电子邮件地址列表 |
from | String | 电子邮件的发送地址,必须是 Gmail 返回的值之一 |
html | String | 如果设置了此参数,能够呈现 HTML 的设备会使用此参数,而不是必需的正文实参;如果电子邮件包含内嵌图片,您可以在 HTML 正文中添加可选的 inline 字段 |
inline | Object | 一个 JavaScript 对象,包含从图片键 (String) 到图片数据 (Blob) 的映射;这假设使用了 html 参数,并且该参数包含对这些图片的引用,格式为 <img src="cid:imageKey" /> |
name | String | 电子邮件发件人的名称(默认:用户的名称) |
reply | String | 用作默认回复地址的电子邮件地址 (默认值:用户的电子邮件地址) |
subject | String | 电子邮件的新主题行,最多 250 个字符。 |
返回
GmailDraft - 新创建的草稿消息。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
createDraftReplyAll(body)
创建一封草稿邮件,使用“回复”地址和相应邮件的所有收件人回复发件人。电子邮件的大小(包括标题)受配额限制。
// Create a draft response to all recipients (except those bcc'd) with an // acknowledgment. const firstThread = GmailApp.getInboxThreads(0, 1)[0]; const message = firstThread.getMessages()[0]; message.createDraftReplyAll('Got your message');
参数
| 名称 | 类型 | 说明 |
|---|---|---|
body | String | 电子邮件的正文。 |
返回
GmailDraft - 新创建的草稿消息。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
createDraftReplyAll(body, options)
使用“回复”地址和所有收件人创建一封回复此邮件的发件人的草稿邮件,并可使用可选实参。
电子邮件可以同时包含纯文本和 HTML 正文。电子邮件的大小(包括标题)受配额限制。
// Create a draft response to all recipients (except those bcc'd) using an HTML // text body. const firstThread = GmailApp.getInboxThreads(0, 1)[0]; const message = firstThread.getMessages()[0]; message.createDraftReplyAll('incapable of HTML', { htmlBody: '<b>some HTML body text</b>', cc: 'another@example.com', });
参数
| 名称 | 类型 | 说明 |
|---|---|---|
body | String | 电子邮件的正文。 |
options | Object | 一个 JavaScript 对象,用于指定高级参数,如下所列。 |
高级参数
| 名称 | 类型 | 说明 |
|---|---|---|
attachments | Blob | 要随电子邮件一起发送的文件数组 |
bcc | String | 以逗号分隔的密送电子邮件地址列表 |
cc | String | 以逗号分隔的抄送电子邮件地址列表 |
from | String | 电子邮件的发送地址,必须是 Gmail 返回的值之一 |
html | String | 如果设置了此参数,能够呈现 HTML 的设备会使用此参数,而不是必需的正文实参;如果电子邮件包含内嵌图片,您可以在 HTML 正文中添加可选的 inline 字段 |
inline | Object | 一个 JavaScript 对象,包含从图片键 (String) 到图片数据 (Blob) 的映射;这假设使用了 html 参数,并且该参数包含对这些图片的引用,格式为 <img src="cid:imageKey" /> |
name | String | 电子邮件发件人的名称(默认:用户的名称) |
reply | String | 用作默认回复地址的电子邮件地址 (默认值:用户的电子邮件地址) |
subject | String | 电子邮件的新主题行,最多 250 个字符。 |
返回
GmailDraft - 新创建的草稿消息。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
forward(recipient)
将此邮件转发给新的收件人。电子邮件的大小(包括标题)受配额限制。
// Forward first message of first inbox thread to recipient1 & recipient2, // both @example.com const firstThread = GmailApp.getInboxThreads(0, 1)[0]; const message = firstThread.getMessages()[0]; message.forward('recipient1@example.com,recipient2@example.com');
参数
| 名称 | 类型 | 说明 |
|---|---|---|
recipient | String | 以逗号分隔的电子邮件地址列表。 |
返回
GmailMessage - 此消息可用于链式调用。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
forward(recipient, options)
将此消息转发给新收件人,并带有可选实参。
电子邮件可以包含纯文本和 HTML 正文。电子邮件的大小(包括标题)受配额限制。
const firstThread = GmailApp.getInboxThreads(0, 1)[0]; const message = firstThread.getMessages()[0]; message.forward('recipient1@example.com,recipient2@example.com', { cc: 'myboss@example.com', bcc: 'mybosses-boss@example.com,vp@example.com', });
参数
| 名称 | 类型 | 说明 |
|---|---|---|
recipient | String | 以逗号分隔的电子邮件地址列表。 |
options | Object | 一个 JavaScript 对象,用于指定高级参数,如下所列。 |
高级参数
| 名称 | 类型 | 说明 |
|---|---|---|
attachments | Blob | 要随电子邮件一起发送的文件数组 |
bcc | String | 以逗号分隔的密送电子邮件地址列表 |
cc | String | 以逗号分隔的抄送电子邮件地址列表 |
from | String | 电子邮件的发送地址,必须是 Gmail 返回的值之一 |
html | String | 如果设置了此参数,能够呈现 HTML 的设备会使用此参数,而不是必需的正文实参;如果电子邮件包含内嵌图片,您可以在 HTML 正文中添加可选的 inline 字段 |
inline | Object | 一个 JavaScript 对象,包含从图片键 (String) 到图片数据 (Blob) 的映射;这假设使用了 html 参数,并且该参数包含对这些图片的引用,格式为 <img src="cid:imageKey" /> |
name | String | 电子邮件发件人的名称(默认:用户的名称) |
no | Boolean | true 如果电子邮件应从通用的“请勿回复”电子邮件地址发送,以阻止收件人回复电子邮件;此选项仅适用于 Google Workspace 账号,不适用于 Gmail 用户 |
reply | String | 用作默认回复地址的电子邮件地址 (默认值:用户的电子邮件地址) |
subject | String | 电子邮件的新主题行,最多 250 个字符。 |
返回
GmailMessage - 此消息可用于链式调用。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
getAttachments()
获取相应消息的所有附件。
返回
GmailAttachment[] - 相应邮件的 Blob 附件数组。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
getAttachments(options)
获取相应消息的所有附件。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
options | Object | 一个 JavaScript 对象,用于指定高级参数,如下所列。 |
高级参数
| 名称 | 类型 | 说明 |
|---|---|---|
include | Boolean | 如果返回的 Blob 附件数组应包含内嵌图片,则为 true(默认值为 true)。true |
include | Boolean | 如果返回的 Blob 附件数组应包含常规(非内嵌)附件,则为 true(默认值为 true)。 |
返回
GmailAttachment[] - 相应邮件的 Blob 附件数组。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
getBcc()
获取此邮件中以逗号分隔的密送收件人。
根据定义,对于所有收到的消息,此属性均为空。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(message.getBcc()); // Log bcc'd addresses
返回
String - 以逗号分隔的此邮件的密送收件人。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
getBody()
获取相应邮件正文的 HTML 内容。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(message.getBody()); // Log contents of the body
返回
String - 相应消息的正文内容。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
getCc()
获取此消息中以逗号分隔的抄送收件人。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(message.getCc()); // Log cc'd addresses
返回
String - 以逗号分隔的此邮件的抄送收件人。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
getDate()
获取相应消息的日期和时间。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(message.getDate()); // Log date and time of the message
返回
Date - 相应消息的日期和时间。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
getFrom()
获取相应消息的发送者。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(message.getFrom()); // Log from address of the message
返回
String - 消息发送者的电子邮件地址。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
getHeader(name)
根据标头名称获取 RFC 2822 标头的值。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox. const message = thread.getMessages()[0]; // Get the first message. Logger.log( message.getHeader('Message-ID')); // Logs the Message-ID RFC 2822 header.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
name | String | RFC 标头的名称,不含用于分隔名称和值的英文冒号。 |
返回
String - 相应标头的值;如果邮件中不存在相应标头,则为空字符串。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
getId()
获取相应消息的 ID。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message const id = message.getId(); const messageById = GmailApp.getMessageById(id); Logger.log( message.getSubject() === messageById.getMessage()); // Always logs true
返回
String - 消息 ID。
getPlainBody()
获取相应邮件正文的内容(不含 HTML 格式)。此方法比 getBody() 更复杂,耗时更长。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(message.getPlainBody()); // Log contents of the body
返回
String - 相应邮件的纯文本正文内容。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
getRawContent()
获取相应消息的原始内容。这相当于 Gmail 界面中的“显示原始邮件”。
返回
String - 相应消息的原始内容。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
getReplyTo()
获取相应邮件的回复地址(通常为发件人)。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(message.getReplyTo()); // Logs reply-to address
返回
String - 用于接收回复的电子邮件地址。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
getSubject()
获取相应邮件的主题。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(message.getSubject()); // Log subject line
返回
String - 相应邮件的主题。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
getThread()
获取包含相应消息的线程。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log( message.getThread().getFirstMessageSubject() === thread.getFirstMessageSubject(), ); // Always logs true
返回
GmailThread - 包含相应邮件的 GmailThread。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
getTo()
获取相应消息的以逗号分隔的收件人。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(message.getTo()); // Log the recipient of message
返回
String - 以逗号分隔的此邮件的收件人。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
isDraft()
获取相应消息是否为草稿。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(`is draft? ${message.isDraft()}`);
返回
Boolean - 相应消息是否为草稿。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
isInChats()
获取相应消息是否为聊天消息。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(`is a chat? ${message.isInChats()}`);
返回
Boolean - 相应消息是否为聊天消息。
isInInbox()
获取相应消息是否位于收件箱中。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(`is in inbox? ${message.isInInbox()}`);
返回
Boolean - 相应消息是否位于收件箱中。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
isInPriorityInbox()
如果相应邮件位于优先收件箱中,则返回 true;否则返回 false。
const thread = GmailApp.getPriorityInboxThreads( 0, 1)[0]; // Get first thread in priority inbox const messages = thread.getMessages(); for (let i = 0; i < messages.length; i++) { // At least one of the messages is in priority inbox Logger.log(`is in priority inbox? ${messages[i].isInPriorityInbox()}`); }
返回
Boolean - 相应邮件是否位于优先收件箱中。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
isInTrash()
获取相应消息是否位于“已删除邮件”文件夹中。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(`is in the trash? ${message.isInTrash()}`);
返回
Boolean - 相应消息是否位于回收站中。
isStarred()
获取相应消息是否已加星标。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(`is starred? ${message.isStarred()}`);
返回
Boolean - 相应邮件是否已加星标。
isUnread()
获取相应消息是否为未读消息。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message Logger.log(`is unread? ${message.isUnread()}`);
返回
Boolean - 相应消息的未读状态。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
markRead()
将邮件标记为已读。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message message.markRead(); // Mark as read
返回
GmailMessage - 此 GmailMessage,可用于链接。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
markUnread()
将邮件标记为未读。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message message.markUnread(); // Mark as unread
返回
GmailMessage - 此 GmailMessage,可用于链接。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
moveToTrash()
将邮件移至回收站。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message message.moveToTrash(); // Move message to trash
返回
GmailMessage - 此 GmailMessage,可用于链接。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
refresh()
从 Gmail 重新加载此消息和关联状态(如果标签、已读状态等发生变化,此方法非常有用)。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message // .. Do bunch of stuff here message.refresh(); // Make sure it's up to date // Do more stuff to message
返回
GmailMessage - 用于链式调用的消息。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
reply(body)
使用回复地址回复此邮件的发件人。电子邮件的大小(包括标题)受配额限制。
// Respond to author of message with acknowledgment const firstThread = GmailApp.getInboxThreads(0, 1)[0]; const message = firstThread.getMessages()[0]; message.reply('Got your message');
参数
| 名称 | 类型 | 说明 |
|---|---|---|
body | String | 电子邮件的正文。 |
返回
GmailMessage - 此消息可用于链式调用。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
reply(body, options)
使用回复地址回复此邮件的发件人,并带有可选实参。
电子邮件可以包含纯文本和 HTML 正文。电子邮件的大小(包括标题)受配额限制。
// Respond with HTML body text const firstThread = GmailApp.getInboxThreads(0, 1)[0]; const message = firstThread.getMessages()[0]; message.reply('incapable of HTML', { htmlBody: '<b>some HTML body text</b>', noReply: true, });
参数
| 名称 | 类型 | 说明 |
|---|---|---|
body | String | 电子邮件的正文。 |
options | Object | 一个 JavaScript 对象,用于指定高级参数,如下所列。 |
高级参数
| 名称 | 类型 | 说明 |
|---|---|---|
attachments | Blob | 要随电子邮件一起发送的文件数组 |
bcc | String | 以逗号分隔的密送电子邮件地址列表 |
cc | String | 以逗号分隔的抄送电子邮件地址列表 |
from | String | 电子邮件的发送地址,必须是 Gmail 返回的值之一 |
html | String | 如果设置了此参数,能够呈现 HTML 的设备会使用此参数,而不是必需的正文实参;如果电子邮件包含内嵌图片,您可以在 HTML 正文中添加可选的 inline 字段 |
inline | Object | 一个 JavaScript 对象,包含从图片键 (String) 到图片数据 (Blob) 的映射;这假设使用了 html 参数,并且该参数包含对这些图片的引用,格式为 <img src="cid:imageKey" /> |
name | String | 电子邮件发件人的名称(默认:用户的名称) |
no | Boolean | true 如果电子邮件应从通用的“请勿回复”电子邮件地址发送,以阻止收件人回复电子邮件;此选项仅适用于 Google Workspace 账号,不适用于 Gmail 用户 |
reply | String | 用作默认回复地址的电子邮件地址 (默认值:用户的电子邮件地址) |
subject | String | 电子邮件的新主题行,最多 250 个字符。 |
返回
GmailMessage - 此消息可用于链式调用。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
replyAll(body)
回复发件人(使用回复地址)以及此邮件的所有收件人。电子邮件的大小(包括标题)受配额限制。
// Respond to all recipients (except bcc'd) of last email in thread with // acknowledgment const firstThread = GmailApp.getInboxThreads(0, 1)[0]; const message = firstThread.getMessages()[0]; message.replyAll('Got your message');
参数
| 名称 | 类型 | 说明 |
|---|---|---|
body | String | 电子邮件的正文。 |
返回
GmailMessage - 此消息可用于链接。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
replyAll(body, options)
使用回复地址和所有收件人回复此邮件的发送者,并带有可选实参。
电子邮件可以包含纯文本和 HTML 正文。电子邮件的大小(包括标题)受配额限制。
// Respond with HTML body text const firstThread = GmailApp.getInboxThreads(0, 1)[0]; const message = firstThread.getMessages()[0]; message.replyAll('incapable of HTML', { htmlBody: '<b>some HTML body text</b>', noReply: true, });
参数
| 名称 | 类型 | 说明 |
|---|---|---|
body | String | 电子邮件的正文。 |
options | Object | 一个 JavaScript 对象,用于指定高级参数,如下所列。 |
高级参数
| 名称 | 类型 | 说明 |
|---|---|---|
attachments | Blob | 要随电子邮件一起发送的文件数组 |
bcc | String | 以逗号分隔的密送电子邮件地址列表 |
cc | String | 以逗号分隔的抄送电子邮件地址列表 |
from | String | 电子邮件的发送地址,必须是 Gmail 返回的值之一 |
html | String | 如果设置了此参数,能够呈现 HTML 的设备会使用此参数,而不是必需的正文实参;如果电子邮件包含内嵌图片,您可以在 HTML 正文中添加可选的 inline 字段 |
inline | Object | 一个 JavaScript 对象,包含从图片键 (String) 到图片数据 (Blob) 的映射;这假设使用了 html 参数,并且该参数包含对这些图片的引用,格式为 <img src="cid:imageKey" /> |
name | String | 电子邮件发件人的名称(默认:用户的名称) |
no | Boolean | true 如果电子邮件应从通用的“请勿回复”电子邮件地址发送,以阻止收件人回复电子邮件;此选项仅适用于 Google Workspace 账号,不适用于 Gmail 用户 |
reply | String | 用作默认回复地址的电子邮件地址 (默认值:用户的电子邮件地址) |
subject | String | 电子邮件的新主题行,最多 250 个字符。 |
返回
GmailMessage - 此消息可用于链式调用。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
star()
为消息添加星标。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message message.star(); // Star the message
返回
GmailMessage - 此 GmailMessage,可用于链接。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/
另请参阅
unstar()
为消息移除星标。
const thread = GmailApp.getInboxThreads(0, 1)[0]; // Get first thread in inbox const message = thread.getMessages()[0]; // Get first message message.unstar(); // Unstar the message
返回
GmailMessage - 此 GmailMessage,可用于链接。
授权
使用此方法的脚本需要通过以下一个或多个范围或相关 REST API 中的相应范围进行授权:
-
https://mail.google.com/