Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Email Headers Using Google Apps Script

I would like to read through my all my Gmail emails' headers to find specific information.

I know there is no access through the GmailApp service (well, pretty sure anyway).

Any ideas on how to get the header information with a solution primarily based in Apps Script?

like image 280
Weehooey Avatar asked Dec 12 '22 20:12

Weehooey


1 Answers

No, email headers are not possible through the Apps Script services. You'll have to go the IMAP or SMTP route for that.

-- UPDATE

You got me curious and looks like you can get the important ones through getRawContent() and manually parse it.

Here is the code you can try -

function processInbox() {
  //get first message in first thread
  var message = GmailApp.getInboxThreads(0,1)[0].getMessages()[0];
  Logger.log(message.getRawContent());
};

and here is the output from a LinkedIn group message -

From: Google APPS users Group Members <[email protected]>
To: Arun Nagarajan <[email protected]>
Message-ID: <[email protected]>
Subject: [2] discussions, [1] comment and [1] job on LinkedIn
MIME-Version: 1.0
Content-Type: multipart/mixed; 
    boundary="----=_Part_35263277_1178500841.1354293878345"
X-LinkedIn-Template: anet_digest_type
X-LinkedIn-Class: GROUPDIGEST
X-LinkedIn-fbl: s-uPmFAdhOYxvH52TwUlkvTF6rOfu4R6CRfjIFaaCOYfXQgGt9OunBRp

------=_Part_35263277_1178500841.1354293878345
Content-Type: multipart/related; 
    boundary="----=_Part_35263278_821958406.1354293878345"

------=_Part_35263278_821958406.1354293878345
Content-Type: multipart/alternative; 
    boundary="----=_Part_35263270_1718315066.1354293878331"

------=_Part_35263270_1718315066.1354293878331
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

message here
<snip>
like image 84
Arun Nagarajan Avatar answered Dec 28 '22 06:12

Arun Nagarajan