Skip to content

Instantly share code, notes, and snippets.

@uwemneku
Created October 30, 2021 14:30
Show Gist options
  • Save uwemneku/64c8af557afa118728fa983e820c48ad to your computer and use it in GitHub Desktop.
Save uwemneku/64c8af557afa118728fa983e820c48ad to your computer and use it in GitHub Desktop.
How to show
const months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
const days = ["Sunday", "Saturday", "Monday", "Tuesday", "Wenesday", "Thursday", "Friday"];
function myFunction() {
let name
let email
const threads = GmailApp.search("category:primary").forEach((item, i, u) => {
item.getMessages().forEach(item => {
const name_email = item.getFrom().replace(/>/g, '').split("<")
if (name_email.length > 1) {
name = name_email[0];
email = name_email[1]
} else {
name = "";
email = name_email[0]
}
const hours = item.getDate().getHours()
let minutes = item.getDate().getMinutes()
if(minutes < 10) minutes = "0" + minutes
const month = months[item.getDate().getMonth()]
const day = days[item.getDate().getUTCDay()]
const year = item.getDate().getFullYear()
const isInPriority = item.isInPriorityInbox()
SpreadsheetApp.openById('1ohfPSq0ZMeiYksvG28j7Vq8OIMOZr8TdNVAUwOKQ2Qs').getSheets()[0]
.appendRow([name, email, `${hours}:${minutes}`, day, month, year, item.getSubject(), (isInPriority ? 'true' : 'false')])
Logger.log([name, email, `${hours}:${minutes}`, day, month, year, item.getSubject(), (isInPriority ? 'true' : 'false')])
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment