Created
December 13, 2014 01:04
-
-
Save kunal732/00ad9ec8e218bd63f272 to your computer and use it in GitHub Desktop.
Shows how to use SendGrid to translate emails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment