Skip to content

Instantly share code, notes, and snippets.

@theindianappguy
Created June 27, 2021 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theindianappguy/1ae32a0c5f3a4361161ebc6cad5d5ac5 to your computer and use it in GitHub Desktop.
Save theindianappguy/1ae32a0c5f3a4361161ebc6cad5d5ac5 to your computer and use it in GitHub Desktop.
Get Email Id By Subject
function onOpen() {
var Ui = SpreadsheetApp.getUi()
var menu = Ui.createAddonMenu()
.addItem("Get Message ID", "getMsgIds")
.addToUi()
}
function getMsgIds() {
var MsgSubject = Browser.inputBox("Enter the subject of the Email");
if (!MsgSubject) {
Browser.msgBox("oh oh, seems you forgot to provide the message subject, please try again. I\n\\n\\n\\n Thank you! \\n\\n Regards, l\n G")
}
if (MsgSubject) {
var Threads = GmailApp.search('subject:' + '"' + MsgSubject + '"')
for (i = 0; i < Threads.length; i++) {
var MsgId = Threads[i].getId()
var Subject = Threads[i].getFirstMessageSubject()
Logger.log(`Subject: ${Subject}, MsgId: ${MsgId}`);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment