SHARE
TWEET

Untitled

a guest Jan 20th, 2020 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // aggiungi menù
  2. function onOpen() {
  3.   var ui = SpreadsheetApp.getUi();
  4.   ui.createMenu('Estrai Email')
  5.       .addItem('Estrai Indirizzi...', 'estraiIndirizzi')
  6.       .addToUi();
  7. }
  8.  
  9. function estraiIndirizzi() {
  10.  
  11.   var ss = SpreadsheetApp.getActiveSpreadsheet();
  12.   var sheet = ss.getActiveSheet();
  13.  
  14.   var search = "subject:AH IT Rimozione mailing list";
  15.  
  16.   // analizza le ultime 50 email per evitare che esploda tutto
  17.   var threads = GmailApp.search(search, 0, 50);
  18.  
  19.   var row, messages, from, email;
  20.  
  21.  for (var i=0; i<threads.length; i++) {
  22.  
  23.       from = threads[i].getMessages()[0].getFrom();
  24.  
  25.  
  26.       if (from.length) {
  27.  
  28.         email = from[0];
  29.         email = email.replace(">", "");
  30.         email = email.replace("<", "");
  31.  
  32.         row   = sheet.getLastRow() + 1;
  33.         // se trova un indirizzo, aggiungilo alla lista
  34.         sheet.getRange(row,1).setValue(email);
  35.       }
  36.    }
  37.   var date = new Date()
  38.   sheet.getRange(1,6).setValue(date)
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top