3

I've found this lovely script from another thread: Get e-mail addresses from Gmail messages received.

It works great! However, what I'm trying to do is pull the contact info from the message body, as a lot of our older emails came from the same [email protected] address.

All of these emails are incoming (via WordPress contact form 7) and they all have the same message body. The first line in the message is always:

From: Name <[email protected]>

What would I need to do to capture the name and email into a spreadsheet?

Ideally, the A column would capture the Name and B column would capture the email address.

1
  • May also try with Email Extractor that may help you.
    – BDRSuite
    Apr 30, 2015 at 18:48

1 Answer 1

2

You would need to write some sort of regex to extract that string from the message.

var threads = GmailApp.getInboxThreads();

for (var t in threads) {

  var messages = threads[t].getMessages[];
  var text = messages[0].getPlainBody();

  var matches = /From:(.*?)<(.*?)>/gi.exec(text);
  if (matches) 
      Logger.log(matches[1] + " :: " + matches[2]);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.