gas-types-detailed
Version:
Detailed Google Apps Script Type Definitions. Forked from Definitely Typed @types/google-apps-script. Adds full documentation and urls.
1,131 lines (1,041 loc) • 93.3 kB
TypeScript
// Type definitions for Google Apps Script 2023-10-28
// Project: https://developers.google.com/apps-script/
// Definitions by: motemen <https://github.com/motemen/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="google-apps-script.types.d.ts" />
/// <reference path="google-apps-script.base.d.ts" />
declare namespace GoogleAppsScript {
namespace Gmail {
/**
* Provides access to Gmail threads, messages, and labels.
*/
interface GmailApp {
/**
* Creates a draft email message. The size of the email (including headers) is quota limited.
*
*
* // The code below creates a draft email with the current date and time.
* var now = new Date();
* GmailApp.createDraft("mike@example.com", "current time", "The time is: " + now.toString());
* https://developers.google.com/apps-script/reference/gmail/gmail-app#createDraft(String,String,String)
* @param recipient comma separated list of email addresses
* @param subject subject of the email
* @param body body of the email
*/
createDraft(recipient: string, subject: string, body: string): GmailDraft;
/**
* Creates a draft email message with optional arguments. The email can contain plain text or an
* HTML body. The size of the email (including headers, but excluding attachments) is quota limited.
*
*
* // Create a draft email with a file from Google Drive attached as a PDF.
* var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
* GmailApp.createDraft('mike@example.com', 'Attachment example', 'Please see attached file.', {
* attachments: [file.getAs(MimeType.PDF)],
* name: 'Automatic Emailer Script'
* });
* https://developers.google.com/apps-script/reference/gmail/gmail-app#createDraft(String,String,String,Object)
* @param recipient the addresses of the recipient
* @param subject the subject line
* @param body the body of the email
* @param options a JavaScript object that specifies advanced parameters, as listed below
*/
createDraft(recipient: string, subject: string, body: string, options: any): GmailDraft;
/**
* Create a new user label of the given name.
*
*
* // Creates the label @FOO and logs label: FOO
* Logger.log("label: " + GmailApp.createLabel("FOO"));
* https://developers.google.com/apps-script/reference/gmail/gmail-app#createLabel(String)
* @param name the name of the new label
*/
createLabel(name: string): GmailLabel;
/**
* Deletes the specified label.
*
*
* // Have to get the label by name first
* var label = GmailApp.getUserLabelByName("FOO");
* GmailApp.deleteLabel(label);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#deleteLabel(GmailLabel)
* @param label the label to delete
*/
deleteLabel(label: GmailLabel): GmailApp;
/**
* Gets a list of the emails that are set up as aliases for this account in Gmail.
*
*
* You can send a message from any of these aliases by using the "from" optional argument.
*
*
* // Log the aliases for this Gmail account and send an email as the first one.
* var me = Session.getActiveUser().getEmail();
* var aliases = GmailApp.getAliases();
* Logger.log(aliases);
* if (aliases.length > 0) {
* GmailApp.sendEmail(me, 'From an alias', 'A message from an alias!', {'from': aliases[0]});
* } else {
* GmailApp.sendEmail(me, 'No aliases found', 'You have no aliases.');
* }
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getAliases()
*/
getAliases(): string[];
/**
* Retrieve an email message draft by ID.
*
*
* Use this in conjunction with getId() on Gmail drafts.
*
*
* // Get the first draft message in your drafts folder
* var draft = GmailApp.getDrafts()[0];
* // Get its ID
* var draftId = draft.getId();
* // Now fetch the same draft using that ID.
* var draftById = GmailApp.getDraft(draftId);
* // Should always log true as they should be the same message
* Logger.log(draft.getMessage().getSubject() == draftById.getMessage().getSubject());
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getDraft(String)
* @param draftId the ID of the draft to retrieve
*/
getDraft(draftId: string): GmailDraft;
/**
* Retrieves all draft messages.
*
*
* // Logs the number of draft messages
* var drafts = GmailApp.getDraftMessages();
* Logger.log(drafts.length);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getDraftMessages()
*/
getDraftMessages(): GmailMessage[];
/**
* Gets all Gmail draft messages.
*
*
* var drafts = GmailApp.getDrafts();
* for (var i = 0; i < drafts.length; i++) {
* Logger.log(drafts[i].getId());
* }
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getDrafts()
*/
getDrafts(): GmailDraft[];
/**
* Retrieves all Inbox threads irrespective of labels.
*
*
* This call will fail when the size of all threads is too large for the system to handle.
* Where the thread size is unknown, and potentially very large, please use the 'paged' call, and
* specify ranges of the threads to retrieve in each call.
*
*
* // Log the subject lines of your Inbox
* var threads = GmailApp.getInboxThreads();
* for (var i = 0; i < threads.length; i++) {
* Logger.log(threads[i].getFirstMessageSubject());
* }
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getInboxThreads()
*/
getInboxThreads(): GmailThread[];
/**
* Retrieves a range of Inbox threads irrespective of labels.
*
*
* // Log the subject lines of up to the first 50 emails in your Inbox
* var threads = GmailApp.getInboxThreads(0, 50);
* for (var i = 0; i < threads.length; i++) {
* Logger.log(threads[i].getFirstMessageSubject());
* }
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getInboxThreads(Integer,Integer)
* @param start the index of the first thread to retrieve
* @param max the maximum number of threads to retrieve
*/
getInboxThreads(start: Integer, max: Integer): GmailThread[];
/**
* Gets the number of unread threads in the inbox.
*
*
* Logger.log("Messages unread in inbox: " + GmailApp.getInboxUnreadCount());
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getInboxUnreadCount()
*/
getInboxUnreadCount(): Integer;
/**
* Gets a message by ID.
*
*
* Use this in conjunction with getId() on Gmail messages.
*
*
* // Get the first message in the first thread of your inbox
* var message = GmailApp.getInboxThreads(0, 1)[0].getMessages()[0];
* // Get its ID
* var messageId = message.getId();
* // Now fetch the same message using that ID.
* var messageById = GmailApp.getMessageById(messageId);
* // Should always log true as they should be the same message
* Logger.log(message.getSubject() == messageById.getSubject());
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getMessageById(String)
* @param id the ID of the message to retrieve
*/
getMessageById(id: string): GmailMessage;
/**
* Retrieve all messages in the specified thread.
*
*
* // Log all the subject lines in the first thread of your inbox
* var thread = GmailApp.getInboxThreads(0, 1)[0];
* var messages = GmailApp.getMessagesForThread(thread);
* for (var i = 0 ; i < messages.length; i++) {
* Logger.log("subject: " + messages[i].getSubject());
* }
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getMessagesForThread(GmailThread)
* @param thread the thread of messages to retrieve
*/
getMessagesForThread(thread: GmailThread): GmailMessage[];
/**
* Retrieve all messages in the specified threads.
*
*
* // Log the subject lines of all messages in the first two threads of your inbox
* var thread = GmailApp.getInboxThreads(0, 2);
* var messages = GmailApp.getMessagesForThreads(thread);
* for (var i = 0 ; i < messages.length; i++) {
* for (var j = 0; j < messages[i].length; j++) {
* Logger.log("subject: " + messages[i][j].getSubject());
* }
* }
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getMessagesForThreads(GmailThread)
* @param threads the threads of messages to retrieve
*/
getMessagesForThreads(threads: GmailThread[]): GmailMessage[][];
/**
* Retrieves all Priority Inbox threads irrespective of labels.
*
*
* This call will fail when the size of all threads is too large for the system to handle.
* Where the thread size is unknown, and potentially very large, please use the 'paged' call, and
* specify ranges of the threads to retrieve in each call.
*
*
* Logger.log("# of messages in your Priority Inbox: " +
* GmailApp.getPriorityInboxThreads().length);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getPriorityInboxThreads()
*/
getPriorityInboxThreads(): GmailThread[];
/**
* Retrieves a range of Priority Inbox threads irrespective of labels.
*
*
* // Will log some number 2 or less
* Logger.log("# of messages in your Priority Inbox: " +
* GmailApp.getPriorityInboxThreads(0, 2).length);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getPriorityInboxThreads(Integer,Integer)
* @param start the index of the first thread to retrieve
* @param max the maximum number of threads to retrieve
*/
getPriorityInboxThreads(start: Integer, max: Integer): GmailThread[];
/**
* Gets the number of unread threads in the Priority Inbox.
*
*
* Logger.log("Number of unread emails in your Priority Inbox : " +
* GmailApp.getPriorityInboxUnreadCount());
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getPriorityInboxUnreadCount()
*/
getPriorityInboxUnreadCount(): Integer;
/**
* Retrieves all spam threads irrespective of labels.
*
*
* This call will fail when the size of all threads is too large for the system to handle.
* Where the thread size is unknown, and potentially very large, please use the 'paged' call, and
* specify ranges of the threads to retrieve in each call.
*
*
* Logger.log("# of total spam threads: " + GmailApp.getSpamThreads().length);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getSpamThreads()
*/
getSpamThreads(): GmailThread[];
/**
* Retrieves a range of spam threads irrespective of labels.
*
*
* // Will log a number at most 5
* Logger.log("# of total spam threads: " + GmailApp.getSpamThreads(0, 5).length);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getSpamThreads(Integer,Integer)
* @param start the index of the first thread to retrieve
* @param max the maximum number of threads to retrieve
*/
getSpamThreads(start: Integer, max: Integer): GmailThread[];
/**
* Gets the number of unread threads that are spam.
*
*
* // Unless you actually read stuff in your spam folder, this should be the same as
* // the number of messages in your spam folder.
* Logger.log("# unread threads that are spam: " + GmailApp.getSpamUnreadCount());
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getSpamUnreadCount()
*/
getSpamUnreadCount(): Integer;
/**
* Retrieves all starred threads irrespective of labels.
*
*
* This call will fail when the size of all threads is too large for the system to handle.
* Where the thread size is unknown, and potentially very large, please use the 'paged' call, and
* specify ranges of the threads to retrieve in each call.
*
*
* // Logs the number of starred threads
* Logger.log("# Starred threads: " + GmailApp.getStarredThreads().length);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getStarredThreads()
*/
getStarredThreads(): GmailThread[];
/**
* Retrieves a range of starred threads irrespective of labels.
*
*
* // Logs the number of starred threads to a maximum of 5
* Logger.log("# Starred threads: " + GmailApp.getStarredThreads(0, 5).length);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getStarredThreads(Integer,Integer)
* @param start the index of the first thread to retrieve
* @param max the maximum number of threads to retrieve
*/
getStarredThreads(start: Integer, max: Integer): GmailThread[];
/**
* Gets the number of unread threads that are starred.
*
*
* Logger.log("# unread and starred: " + GmailApp.getStarredUnreadCount());
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getStarredUnreadCount()
*/
getStarredUnreadCount(): Integer;
/**
* Gets a thread by ID.
*
*
* Use this in conjunction with getId() on Gmail threads.
*
*
* // Thread IDs can also be found in the location bar when you have a thread open in Gmail
* // get first inbox thread
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* // Get the same thread by ID
* var threadById = GmailApp.getThreadById(firstThread.getId());
* // Verify they are the same
* Logger.log(firstThread.getFirstMessageSubject() == threadById.getFirstMessageSubject());
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getThreadById(String)
* @param id the ID of the thread to retrieve
*/
getThreadById(id: string): GmailThread;
/**
* Retrieves all trash threads irrespective of labels.
*
*
* This call will fail when the size of all threads is too large for the system to handle.
* Where the thread size is unknown, and potentially very large, please use the 'paged' call, and
* specify ranges of the threads to retrieve in each call.
*
*
* Logger.log("# of total trash threads: " + GmailApp.getTrashThreads().length);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getTrashThreads()
*/
getTrashThreads(): GmailThread[];
/**
* Retrieves a range of trash threads irrespective of labels.
*
*
* // Will log a number at most 5
* Logger.log("# of total trash threads: " + GmailApp.getTrashThreads(0, 5).length);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getTrashThreads(Integer,Integer)
* @param start the index of the first thread to retrieve
* @param max the maximum number of threads to retrieve
*/
getTrashThreads(start: Integer, max: Integer): GmailThread[];
/**
* Retrieves a label given the label name.
*
*
* var labelObject = GmailApp.getUserLabelByName("myLabel");
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getUserLabelByName(String)
* @param name the name of the label to retrieve
*/
getUserLabelByName(name: string): GmailLabel;
/**
* Retrieves a list of user-created labels.
*
*
* // Logs all of the names of your labels
* var labels = GmailApp.getUserLabels();
* for (var i = 0; i < labels.length; i++) {
* Logger.log("label: " + labels[i].getName());
* }
* https://developers.google.com/apps-script/reference/gmail/gmail-app#getUserLabels()
*/
getUserLabels(): GmailLabel[];
/**
* Marks this message read and forces the message to refresh.
*
*
* // Mark the first message in the first thread of your inbox as read
* var message = GmailApp.getInboxThreads(0, 1)[0].getMessages()[0];
* GmailApp.markMessageRead(message);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#markMessageRead(GmailMessage)
* @param message the message to mark as read
*/
markMessageRead(message: GmailMessage): GmailApp;
/**
* Marks this message unread and forces the message to refresh.
*
*
* // Mark the first message in the first thread of your inbox as unread
* var message = GmailApp.getInboxThreads(0, 1)[0].getMessages()[0];
* GmailApp.markMessageUnread(message);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#markMessageUnread(GmailMessage)
* @param message the message to mark as unread
*/
markMessageUnread(message: GmailMessage): GmailApp;
/**
* Marks these messages read and forces the messages to refresh.
*
*
* // Mark first three messages in the first inbox thread as read.
* // Assumes that the first inbox thread has 3 messages in it.
* var threadMessages = GmailApp.getInboxThreads(0, 1)[0].getMessages();
* var messages = [threadMessages[0], threadMessages[1], threadMessages[2]];
* GmailApp.markMessagesRead(thread.getMessages());
* https://developers.google.com/apps-script/reference/gmail/gmail-app#markMessagesRead(GmailMessage)
* @param messages an array of messages to mark as read
*/
markMessagesRead(messages: GmailMessage[]): GmailApp;
/**
* Marks these messages unread and forces the messages to refresh.
*
*
* // Mark first three messages in the first inbox thread as unread.
* // Assumes that the first inbox thread has 3 messages in it
* var threadMessages = GmailApp.getInboxThreads(0, 1)[0].getMessages();
* var messages = [threadMessages[0], threadMessages[1], threadMessages[2]];
* GmailApp.markMessagesUnread(thread.getMessages());
* https://developers.google.com/apps-script/reference/gmail/gmail-app#markMessagesUnread(GmailMessage)
* @param messages an array of messages to mark as unread
*/
markMessagesUnread(messages: GmailMessage[]): GmailApp;
/**
* Marks this thread as important and forces the thread to refresh.
*
*
* // Marks first inbox thread as important
* var thread = GmailApp.getInboxThreads(0, 1)[0];
* GmailApp.markThreadImportant(thread);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#markThreadImportant(GmailThread)
* @param thread the thread to mark as important
*/
markThreadImportant(thread: GmailThread): GmailApp;
/**
* Marks this thread as read and forces the thread to refresh.
*
*
* // Marks first inbox thread as read
* var thread = GmailApp.getInboxThreads(0, 1)[0];
* GmailApp.markThreadRead(thread);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#markThreadRead(GmailThread)
* @param thread the thread to mark as read
*/
markThreadRead(thread: GmailThread): GmailApp;
/**
* Marks this thread as unimportant and forces the thread to refresh.
*
*
* // Marks first inbox thread as unimportant
* var thread = GmailApp.getInboxThreads(0, 1)[0];
* GmailApp.markThreadUnimportant(thread);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#markThreadUnimportant(GmailThread)
* @param thread the thread to mark as unimportant
*/
markThreadUnimportant(thread: GmailThread): GmailApp;
/**
* Marks this thread unread and forces the thread to refresh.
*
*
* // Marks first inbox thread as unread
* var thread = GmailApp.getInboxThreads(0, 1)[0];
* GmailApp.markThreadUnread(thread);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#markThreadUnread(GmailThread)
* @param thread the thread to mark as unread
*/
markThreadUnread(thread: GmailThread): GmailApp;
/**
* Marks these threads as important and forces the threads to refresh.
*
*
* // Marks first two threads in inbox as important
* var threads = GmailApp.getInboxThreads(0, 2);
* GmailApp.markThreadsImportant(threads);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#markThreadsImportant(GmailThread)
* @param threads an array of threads to mark as important
*/
markThreadsImportant(threads: GmailThread[]): GmailApp;
/**
* Marks these threads as read and forces the threads to refresh.
*
*
* // Marks first two threads in inbox as read
* var threads = GmailApp.getInboxThreads(0, 2);
* GmailApp.markThreadsRead(threads);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#markThreadsRead(GmailThread)
* @param threads an array of threads to mark as read
*/
markThreadsRead(threads: GmailThread[]): GmailApp;
/**
* Marks these threads as unimportant and forces the threads to refresh.
*
*
* // Marks first two threads in inbox as unimportant
* var threads = GmailApp.getInboxThreads(0, 2);
* GmailApp.markThreadsUnimportant(threads);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#markThreadsUnimportant(GmailThread)
* @param threads an array of threads to mark as unimportant
*/
markThreadsUnimportant(threads: GmailThread[]): GmailApp;
/**
* Marks these threads as unread and forces the threads to refresh.
*
*
* // Marks first two threads in inbox as unread
* var threads = GmailApp.getInboxThreads(0, 2);
* GmailApp.markThreadsUnread(threads);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#markThreadsUnread(GmailThread)
* @param threads an array of threads to mark as unread
*/
markThreadsUnread(threads: GmailThread[]): GmailApp;
/**
* Moves the message to the trash and forces the message to refresh.
*
*
* // Move the first message in your inbox to trash
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* var firstMessage = firstThread.getMessages()[0];
* GmailApp.moveMessageToTrash(firstMessage);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#moveMessageToTrash(GmailMessage)
* @param message the message to be trashed
*/
moveMessageToTrash(message: GmailMessage): GmailApp;
/**
* Moves the specified messages to the trash and forces the messages to refresh.
*
*
* // Move first two messages in your inbox to trash
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* var messages = firstThread.getMessages();
* var toDelete = [messages[0], messages[1]];
* GmailApp.moveMessagesToTrash(toDelete);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#moveMessagesToTrash(GmailMessage)
* @param messages the messages to be trashed
*/
moveMessagesToTrash(messages: GmailMessage[]): GmailApp;
/**
* Moves this thread to the archive and forces the thread to refresh.
*
*
* // Archive the first thread in your inbox
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* GmailApp.moveThreadToArchive(firstThread);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#moveThreadToArchive(GmailThread)
* @param thread the thread to be archive
*/
moveThreadToArchive(thread: GmailThread): GmailApp;
/**
* Moves this thread to the inbox and forces the thread to refresh.
*
*
* // Find a thread not already in your inbox
* var thread = GmailApp.search("-in:inbox")[0]; // Get the first one
* GmailApp.moveThreadToInbox(thread);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#moveThreadToInbox(GmailThread)
* @param thread the thread to be moved to the inbox
*/
moveThreadToInbox(thread: GmailThread): GmailApp;
/**
* Moves this thread to spam and forces the thread to refresh.
*
*
* // Tag first thread in inbox as spam
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* GmailApp.moveThreadToSpam(firstThread);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#moveThreadToSpam(GmailThread)
* @param thread the thread to be moved to spam
*/
moveThreadToSpam(thread: GmailThread): GmailApp;
/**
* Moves this thread to the trash and forces the thread to refresh.
*
*
* // Move first thread in inbox to trash
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* GmailApp.moveThreadToTrash(firstThread);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#moveThreadToTrash(GmailThread)
* @param thread the thread to be trashed
*/
moveThreadToTrash(thread: GmailThread): GmailApp;
/**
* Moves these threads to the archive and forces the threads to refresh.
*
*
* // Move first two threads in your inbox to the archive
* var firstTwoThreads = GmailApp.getInboxThreads(0,2);
* GmailApp.moveThreadsToArchive(firstTwoThreads);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#moveThreadsToArchive(GmailThread)
* @param threads an array of threads to be archived
*/
moveThreadsToArchive(threads: GmailThread[]): GmailApp;
/**
* Moves these threads to the inbox and forces the threads to refresh.
*
*
* // Find two threads not already in your inbox
* var firstTwoThreads = GmailApp.search("-in:inbox", 0, 2);
* GmailApp.moveThreadsToInbox(firstTwoThreads);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#moveThreadsToInbox(GmailThread)
* @param threads an array of threads to be moved to the inbox
*/
moveThreadsToInbox(threads: GmailThread[]): GmailApp;
/**
* Moves these threads to spam and forces the threads to refresh.
*
*
* // Move first two threads in your inbox to spam
* var firstTwoThreads = GmailApp.getInboxThreads(0,2);
* GmailApp.moveThreadsToSpam(firstTwoThreads);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#moveThreadsToSpam(GmailThread)
* @param threads an array of threads to be moved to spam
*/
moveThreadsToSpam(threads: GmailThread[]): GmailApp;
/**
* Moves these threads to the trash and forces the threads to refresh.
*
*
* // Move first two threads in your inbox to trash
* var firstTwoThreads = GmailApp.getInboxThreads(0,2);
* GmailApp.moveThreadsToTrash(firstTwoThreads);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#moveThreadsToTrash(GmailThread)
* @param threads an array of threads to be trashed
*/
moveThreadsToTrash(threads: GmailThread[]): GmailApp;
/**
* Reloads the message and associated state from Gmail (useful in case the labels, read state,
* etc., have changed).
*
*
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* var firstMessage = firstThread.getMessages()[0];
* // ...Do something that may take a while here....
* GmailApp.refreshMessage(firstMessage);
* // ...Do more stuff with firstMessage...
* https://developers.google.com/apps-script/reference/gmail/gmail-app#refreshMessage(GmailMessage)
* @param message the message to be refreshed
*/
refreshMessage(message: GmailMessage): GmailApp;
/**
* Reloads the messages and associated state from Gmail (useful in case the labels, read state,
* etc., have changed).
*
*
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* var coupleOfMessages = firstThread.getMessages().slice(0, 2);
* // ...Do something that may take a while here....
* GmailApp.refreshMessages(coupleOfMessages);
* // ...Do more stuff with coupleOfMessages...
* https://developers.google.com/apps-script/reference/gmail/gmail-app#refreshMessages(GmailMessage)
* @param messages the messages to be refreshed
*/
refreshMessages(messages: GmailMessage[]): GmailApp;
/**
* Reloads the thread and associated state from Gmail (useful in case the labels, read state,
* etc., have changed).
*
*
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* // ...Do something that may take a while here....
* GmailApp.refreshThread(firstThread);
* // ... Do more stuff with the thread ...
* https://developers.google.com/apps-script/reference/gmail/gmail-app#refreshThread(GmailThread)
* @param thread the thread to be refreshed
*/
refreshThread(thread: GmailThread): GmailApp;
/**
* Reloads the threads and associated state from Gmail (useful in case the labels, read state,
* etc., have changed).
*
*
* var threads = GmailApp.getInboxThreads(0, 3);
* // ...Do something that may take a while here....
* GmailApp.refreshThreads(threads);
* // ... Do more stuff with threads ...
* https://developers.google.com/apps-script/reference/gmail/gmail-app#refreshThreads(GmailThread)
* @param threads the threads to be refreshed
*/
refreshThreads(threads: GmailThread[]): GmailApp;
/**
* Search Gmail with the given query.
*
*
* This call will fail when the size of all threads is too large for the system to handle.
* Where the thread size is unknown, and potentially very large, please use the 'paged' call, and
* specify ranges of the threads to retrieve in each call.
*
*
* // Find starred messages with subject IMPORTANT
* var threads = GmailApp.search('is:starred subject:"IMPORTANT"');
* https://developers.google.com/apps-script/reference/gmail/gmail-app#search(String)
* @param query the search query, as you would type it into Gmail
*/
search(query: string): GmailThread[];
/**
* Search Gmail with the given query.
*
*
* // Find starred messages with subject IMPORTANT and return second batch of 10.
* // Assumes there are at least 11 of them, otherwise this will return an empty array.
* var threads = GmailApp.search('is:starred subject:"IMPORTANT"', 10, 10);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#search(String,Integer,Integer)
* @param query the search query, as you would type it into Gmail
* @param start the index of the starting thread
* @param max the maximum number of threads to return
*/
search(query: string, start: Integer, max: Integer): GmailThread[];
/**
* Sends an email message. The size of the email (including headers) is quota limited.
*
*
* // The code below will send an email with the current date and time.
* var now = new Date();
* GmailApp.sendEmail("mike@example.com", "current time", "The time is: " + now.toString());
* https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String)
* @param recipient comma separated list of email addresses
* @param subject subject of the email (250 characters maximum)
* @param body body of the email
*/
sendEmail(recipient: string, subject: string, body: string): GmailApp;
/**
* Sends an email message with optional arguments. The email can contain plain text or an HTML
* body. The size of the email (including headers, but excluding attachments) is quota limited.
*
*
* // Send an email with a file from Google Drive attached as a PDF.
* var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
* GmailApp.sendEmail('mike@example.com', 'Attachment example', 'Please see the attached file.', {
* attachments: [file.getAs(MimeType.PDF)],
* name: 'Automatic Emailer Script'
* });
* https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String,Object)
* @param recipient the addresses of the recipient
* @param subject the subject line (250 characters maximum)
* @param body the body of the email
* @param options a JavaScript object that specifies advanced parameters, as listed below
*/
sendEmail(recipient: string, subject: string, body: string, options: any): GmailApp;
/**
* Sets the current message
* access token that enables the script to access the current GmailMessage properties.
*
*
* Only Google Workspace Add-on projects using Gmail current message scopes
* require this method.
*
*
* function handleAddonActionEvent(e) {
* var accessToken = e.messageMetadata.accessToken;
* var messageId = e.messageMetadata.messageId;
* GmailApp.setCurrentMessageAccessToken(accessToken);
* var mailMessage = GmailApp.getMessageById(messageId);
* // Do something with mailMessage
* }
* https://developers.google.com/apps-script/reference/gmail/gmail-app#setCurrentMessageAccessToken(String)
* @param accessToken the temporary access token obtained from a Gmail add-on action event object.
*/
setCurrentMessageAccessToken(accessToken: string): void;
/**
* Adds a star to this message and forces the message to refresh.
*
*
* // Stars the first message in the first thread in your inbox
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* var message = firstThread.getMessages()[0];
* GmailApp.starMessage(message);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#starMessage(GmailMessage)
* @param message the message to star
*/
starMessage(message: GmailMessage): GmailApp;
/**
* Adds stars to these messages and forces the messages to refresh.
*
*
* // Stars the first three messages in the first thread in your inbox
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* var coupleOfMessages = firstThread.getMessages().slice(0, 3);
* GmailApp.starMessages(coupleOfMessages);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#starMessages(GmailMessage)
* @param messages an array of messages to star
*/
starMessages(messages: GmailMessage[]): GmailApp;
/**
* Removes a star from this message and forces the message to refresh.
*
*
* // Unstars the first message in the first thread in your inbox
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* var message = firstThread.getMessages()[0];
* GmailApp.unstarMessage(message);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#unstarMessage(GmailMessage)
* @param message the message to unstar
*/
unstarMessage(message: GmailMessage): GmailApp;
/**
* Removes stars from these messages and forces the messages to refresh.
*
*
* // Unstars the first three messages in the first thread in your inbox
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* var coupleOfMessages = firstThread.getMessages().slice(0, 3);
* GmailApp.unstarMessages(coupleOfMessages);
* https://developers.google.com/apps-script/reference/gmail/gmail-app#unstarMessages(GmailMessage)
* @param messages an array of messages to unstar
*/
unstarMessages(messages: GmailMessage[]): GmailApp;
/** @deprecated DO NOT USE */ getChatThreads(): GmailThread[];
/** @deprecated DO NOT USE */ getChatThreads(start: Integer, max: Integer): GmailThread[];
}
/**
* An attachment from Gmail. This is a regular Blob except that it has an extra getSize() method that is faster than calling
* getBytes().length and does not count against the Gmail read quota.
*
* // Logs information about any attachments in the first 100 inbox threads.
* var threads = GmailApp.getInboxThreads(0, 100);
* var msgs = GmailApp.getMessagesForThreads(threads);
* for (var i = 0 ; i < msgs.length; i++) {
* for (var j = 0; j < msgs[i].length; j++) {
* var attachments = msgs[i][j].getAttachments();
* for (var k = 0; k < attachments.length; k++) {
* Logger.log('Message "%s" contains the attachment "%s" (%s bytes)',
* msgs[i][j].getSubject(), attachments[k].getName(), attachments[k].getSize());
* }
* }
* }
*/
interface GmailAttachment {
/**
* Returns a copy of this blob.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#copyBlob()
*/
copyBlob(): Base.Blob;
/**
* Return the data inside this object as a blob converted to the specified content type. This
* method adds the appropriate extension to the filename—for example, "myfile.pdf". However, it
* assumes that the part of the filename that follows the last period (if any) is an existing
* extension that should be replaced. Consequently, "ShoppingList.12.25.2014" becomes
* "ShoppingList.12.25.pdf".
*
*
* To view the daily quotas for conversions, see Quotas for Google
* Services. Newly created Google Workspace domains might be temporarily subject to stricter
* quotas.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#getAs(String)
* @param contentType The MIME type to convert to. For most blobs, 'application/pdf' is the only valid option. For images in BMP, GIF, JPEG, or PNG format, any of 'image/bmp', 'image/gif', 'image/jpeg', or 'image/png' are also valid.
*/
getAs(contentType: string): Base.Blob;
/**
* Gets the data stored in this blob.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#getBytes()
*/
getBytes(): Byte[];
/**
* Gets the content type of the bytes in this blob.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#getContentType()
*/
getContentType(): string;
/**
* Gets the data of this blob as a String with UTF-8 encoding.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#getDataAsString()
*/
getDataAsString(): string;
/**
* Gets the data of this blob as a string with the specified encoding.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#getDataAsString(String)
* @param charset The charset to use in encoding the data in this blob as a string.
*/
getDataAsString(charset: string): string;
/**
* Gets the SHA1 content hash for this attachment. This method does not count against the Gmail
* read quota.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#getHash()
*/
getHash(): string;
/**
* Gets the name of this blob.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#getName()
*/
getName(): string;
/**
* Gets the size of this attachment. This method is faster than calling getBytes().length and does not count against the Gmail read quota.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#getSize()
*/
getSize(): Integer;
/**
* Returns whether this blob is a Google Workspace file (Sheets, Docs, etc.).
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#isGoogleType()
*/
isGoogleType(): boolean;
/**
* Sets the data stored in this blob.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#setBytes(Byte)
* @param data The new data.
*/
setBytes(data: Byte[]): Base.Blob;
/**
* Sets the content type of the bytes in this blob.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#setContentType(String)
* @param contentType The new contentType.
*/
setContentType(contentType: string): Base.Blob;
/**
* Sets the content type of the bytes in this blob based on the file extension. The contentType is
* null if it cannot be guessed from its extension.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#setContentTypeFromExtension()
*/
setContentTypeFromExtension(): Base.Blob;
/**
* Sets the data of this blob from a string with UTF-8 encoding.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#setDataFromString(String)
* @param string The string data.
*/
setDataFromString(string: string): Base.Blob;
/**
* Sets the data of this blob from a string with the specified encoding.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#setDataFromString(String,String)
* @param string The string data.
* @param charset The charset to use in interpreting the string as bytes.
*/
setDataFromString(string: string, charset: string): Base.Blob;
/**
* Sets the name of this blob.
* https://developers.google.com/apps-script/reference/gmail/gmail-attachment#setName(String)
* @param name The new name.
*/
setName(name: string): Base.Blob;
/** @deprecated DO NOT USE */ getAllBlobs(): Base.Blob[];
}
/**
* A user-created draft message in a user's Gmail account.
*/
interface GmailDraft {
/**
* Deletes this draft message.
*
*
* var draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder
* draft.deleteDraft();
* draft.getMessage(); // Throws exception.
* https://developers.google.com/apps-script/reference/gmail/gmail-draft#deleteDraft()
*/
deleteDraft(): void;
/**
* Gets the ID of this draft message.
*
*
* var draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder
* var draftId = draft.getId();
* var draftById = GmailApp.getDraft(draftId);
* Logger.log(draft.getMessage().getSubject() == draftById.getMessage().getSubject());
* https://developers.google.com/apps-script/reference/gmail/gmail-draft#getId()
*/
getId(): string;
/**
* Returns a GmailMessage representing this draft.
*
*
* var draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder
* var message = draft.getMessage();
* Logger.log(message.getSubject());
* https://developers.google.com/apps-script/reference/gmail/gmail-draft#getMessage()
*/
getMessage(): GmailMessage;
/**
* Returns the ID of the GmailMessage representing this draft.
*
*
* var draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder
* var messageId = draft.getMessageId();
* Logger.log(messageId == draft.getMessage().getId());
* https://developers.google.com/apps-script/reference/gmail/gmail-draft#getMessageId()
*/
getMessageId(): string;
/**
* Sends this draft email message. The size of the email (including headers) is quota limited.
*
*
* var draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder
* var msg = draft.send(); // Send it
* Logger.log(msg.getDate()); // Should be approximately the current timestamp
* https://developers.google.com/apps-script/reference/gmail/gmail-draft#send()
*/
send(): GmailMessage;
/**
* Replaces the contents of this draft message. The size of the email (including headers) is quota limited.
*
*
* // The code below will update a draft email with the current date and time.
* var draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder
* var now = new Date();
* draft.update("mike@example.com", "current time", "The time is: " + now.toString());
* https://developers.google.com/apps-script/reference/gmail/gmail-draft#update(String,String,String)
* @param recipient comma separated list of email addresses
* @param subject subject of the email (250 characters maximum)
* @param body body of the email
*/
update(recipient: string, subject: string, body: string): GmailDraft;
/**
* Replaces the contents of this draft message using optional arguments. The email can contain
* plain text or an HTML body. The size of the email (including headers) is quota limited.
*
*
* // Update a draft email with a file from Google Drive attached as a PDF.
* var draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder
* var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
* draft.update('mike@example.com', 'Attachment example', 'Please see attached file.', {
* attachments: [file.getAs(MimeType.PDF)],
* name: 'Automatic Emailer Script'
* });
* https://developers.google.com/apps-script/reference/gmail/gmail-draft#update(String,String,String,Object)
* @param recipient comma separated list of email addresses
* @param subject subject of the email (250 characters maximum)
* @param body body of the email
* @param options a JavaScript object that specifies advanced parameters, as listed below
*/
update(recipient: string, subject: string, body: string, options: any): GmailDraft;
}
/**
* A user-created label in a user's Gmail account.
*/
interface GmailLabel {
/**
* Adds this label to the given thread and forces the thread to refresh (GmailThread.refresh()).
*
*
* // label the first thread in the inbox with the label MyLabel
* var label = GmailApp.getUserLabelByName("MyLabel");
* var firstThread = GmailApp.getInboxThreads(0,1)[0];
* label.addToThread(firstThread);
* https://developers.google.com/apps-script/reference/gmail/gmail-label#addToThread(GmailThread)
* @param thread The thread to be labeled.
*/
addToThread(thread: GmailThread): GmailLabel;
/**
* Adds this label to the given threads and forces the threads to refresh. You can add labels for
* up to 100 threads per batch.
*
*
* // label the first three threads in the inbox with the label MyLabel
* var label = GmailApp.getUserLabelByName("MyLabel");
* var threads = GmailApp.getInboxThre