Skip to content

Instantly share code, notes, and snippets.

Last active January 3, 2022 14:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Google App Script
1. Check if there are any new messages with “DMARC Reports” label in my GMail, and
2. if yes, then get the attached file and put it in the “DMARC Reports” folder in my GDrive.
3. Then send me an email with a report about what happened.
// GmailApp:
// DriveApp:
const labelName = "DMARC reports";
const folderName = "DMARC reports";
function importReports() {
const label = GmailApp.getUserLabelByName(labelName);
if (label.getUnreadCount() === 0) {
let report = "";
const say = (string) => {
report += `\n${string}`;
say(`Found ${label.getUnreadCount()} new messages`);
const unreadThreads = label.getThreads().filter((t) => t.isUnread());
const folder = DriveApp.getFoldersByName(folderName).next();
unreadThreads.forEach((thread) => {
const attachment = thread.getMessages()[0].getAttachments()[0];
const file = DriveApp.createFile(attachment.getAllBlobs()[0]);
GmailApp.sendEmail("", "New DMARC reports", report);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment