For Day 3 of this series, I wanted to start diving into an application of Machine Learning. This has long been one of my favorite topics in Computer Science. For this post I wanted to touch upon Natural Language Processing. It’s a field of artificial intelligence (AI) that focuses on the ability for machines to manipulate Natural Language and derive meaning from it. It probably sounds badass because it is.


Sentiment Analysis with TextBlob

In particular I want to focus on Sentiment Analysis and mashing that up with Email. In this blog post I’m going to create a quick Python Flask application with the SendGrid Parse Webhook and a Python Lib called TextBlob ( that will get the sentiment of every incoming email and respond back accordingly.

You can imagine if this email address were to be the first responder when a customer emails in for support on your current product. It could email back a different, unique response if the message is positive or negative.


  • SendGrid account to get incoming & send outgoing emails with your app  (
  • SendGrid Python Lib
    • $ pip install sendgrid
  • Flask:
    • $ pip install flask
  • Textblob:
    • $ pip install -U textblob
    • $ python -m textblob.download_corpora

Sample Code:

In Action

Below are two images of the above code in action. The first image shows the scenario of a happy customer and the second of a fictitious upset customer.


Over the next few weeks, I’m going to continue writing about different technologies, so check back every Monday, Wednesday, and Friday for new tech posts! You can also visit my intro post that will have an updated list of everything I’ve written.

Meet Kunal, Developer Evangelist at-large for SendGrid and home-grown New Jersey hacker. He previously ran General Machines, which developed Deaftel - a phone service for the deaf that converts voice to text and text back into voice over a phone call. Since March 2013, Kunal has been working as a Developer Evangelist at SendGrid, helping enable developers to get the tools and resources they need to make awesome, creative stuff.