Extract useful information from notification emails

TL/DR: Extract relevant information from notification emails and add them to your Analytics or CRM system to follow up on.


Linkedi Notification Email

Linkedin Notification Email

The above image is a typical email notification from Linkedin to let you know that someone has clicked the Like button on one of your recent Posts. It you wanted to add this persons details in to your CRM system so that you or one of your co-workers might follow up with them in the future or if you wanted to gather some Analytics data on successful posts, it is possible to extract this information easily and automatically from the email.

In some cases, an email notification such as this one is the only way to gather the information you need as the service sending you the email notification may not have any API or any other way to export data, so parsing the email might be your only alternative.

The first step is that the notification emails need to go somewhere. This can be a dedicated email address set up specifically to recive email notifications, or you could set up a Forwarding rule in your inbox to automatically forward any incoming notification emails to a dedicated email address.

The next step is to use a email service such as MailGun to create that dedicated email address so that you can set up an email address such as notifcations @ mydomain dot com.  When MailGun receives an email to your chosen address, you can create a Route to POST on the content and headers of the email to your own application to store or parse.

For example, here is a Route you might set up in MailGun to forward on your notification email:

match_recipient(“notifications@mydomain.com”) forward(“http://mydomain.com/mailgun/receive_email”)

On your website, you would need to create a function or script that is ready to receive the information from mailgun:

$posted_data = file_get_contents(“php://input”);

You could use this PHP snippet to retrieve the incoming information (don’t forget to sanitize it first!) and log in, or process it on the fly.

Your next step would be to parse the incoming content from Mailgun. Mailgun sends you on plenty of information and you probably don’t want all of it.

The kind of parsing you do will depend on the content of the email you are working on. If you are going to receive different emails from different sources then you might want to create functions to parse several different email templates and use the email subject line as the marker to know which template to use.

To retrieve the subject of the email that Mailgun has POSTed to your application, use:

$subject = $posted_data[‘Thread-Topic’]; // store the email subject line

Then depending on your subject line, you could send the email content to a function you have prepared to parse the data out of that template.


$content = $posted_data[‘body-plain’]

switch ($subject)
case “Joe Bloggs likes your update”:
// Parse the content of a Linkedin Notification Email
$parsed_email_content = $this->parse->linkedin_email($content);

If you can parse the email content you would end up with a nice structured array of data from the body of the email, ready to save it directly in to your CRM package such as Salesforce or Analytics package.

‘name’=>’Joe Bloggs’,
‘Image’ => XXX,


You could go a little further too and determine the persons Gender based on their name so that you have further information to store.

Leave a Reply

Your email address will not be published. Required fields are marked *