For todays post I wanted to explore a use case for the SendGrid API, that I personally don’t see too often. That use case is mashing up a Machine Translation API with our mail API and webhook. I want to create an email address that lets me communicate with my coworkers and friends that I have been lucky to make in Brazil. How this will work: I’m going to create an application that will translate any email that I send out into portuguese. Any email that gets sent to that address will be translated back into english. The concept is pretty simple and our API makes this type of communication really easy. Requirements SendGrid Account (www.sendgrid.com/free) Translation API (I’m using the Google Translate Python module, https://github.com/terryyin/google-translate-python) Lets Start Just like we did in the last Code Challenge post with Orchestrate, I’m going to use our parse webhook and create a domain name for receiving incoming mail. I’m going to use: brazil.bymail.in , this means any email sent to firstname.lastname@example.org will be sent to my Python application. Here is the code: from flask import Flask, request from translate import Translator import sendgrid app = Flask(__name__) sg = sendgrid.SendGridClient('username', 'password') @app.route ('/incoming', methods =['POST']) def trans(): subject = request.form['subject'] sender = request.form['from'] recip = request.form['to'] body = request.form ['text'] translator = Translator(to_lang="pt") trans_subject = translator.translate(subject) trans_body = translator.translate(body) #send translated: message = sendgrid.Mail() message.add_to(sender) message.set_subject(trans_subject) message.set_html(trans_body) message.set_text(trans_body) message.set_from(recip) status, msg = sg.send(message) return "OK" if __name__=='__main__': app.run(debug=True) This code is just for sample use. It will take any email it gets, translate it into Portuguese and email the translated content back to the sender. This is pretty simple, fun and powerful. I’ve posted some photos that showcase the translation: 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.