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 something@brazil.bymail.in 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.
Best Practices, Email Marketing, Product How to Create and Execute an Email Sunsetting Strategy Devin Chasanoff April 19, 2018 • 3 min read
Product New Sender Authentication Improves Email Delivery Without Frustration Lindsey Weinig April 17, 2018 • 2 min read
Best Practices Top Tips to Avoid Spam Filters When Sending Emails Elmer Thomas December 23, 2017 • 6 min read
Email Marketing What is an Email Blast? 5 Tips for Rethinking Your Email Strategy Kelsey Bernius November 4, 2016 • 3 min read
Best Practices Email Bounce Management: Soft Bounces vs. Hard Bounces Carly Brantz February 24, 2014 • 3 min read
Best Practices, Product SMTP Relay Service 101 [Back to Basics] Carly Brantz February 7, 2013 • 4 min read