Skip to content

Commit 67c0c1d

Browse files
author
Jon Wayne Parrott
committed
Updating flex sendgrid sample.
Change-Id: I298f6c88a42b416bdefc666b570e0a36f06fd82f
1 parent bfef34d commit 67c0c1d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

appengine/flexible/sendgrid/main.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from flask import Flask, render_template, request
2020
import sendgrid
21+
from sendgrid.helpers import mail
2122

2223
# [START config]
2324
SENDGRID_API_KEY = os.environ['SENDGRID_API_KEY']
@@ -40,19 +41,18 @@ def send_email():
4041
return ('Please provide an email address in the "to" query string '
4142
'parameter.'), 400
4243

43-
sg = sendgrid.SendGridClient(SENDGRID_API_KEY)
44+
sg = sendgrid.SendGridAPIClient(apikey=SENDGRID_API_KEY)
4445

45-
message = sendgrid.Mail(
46-
to=to,
47-
subject='This is a test email',
48-
html='<p>Example HTML body.</p>',
49-
text='Example text body.',
50-
from_email=SENDGRID_SENDER)
46+
to_email = mail.Email(to)
47+
from_email = mail.Email(SENDGRID_SENDER)
48+
subject = 'This is a test email'
49+
content = mail.Content('text/plain', 'Example message.')
50+
message = mail.Mail(from_email, subject, to_email, content)
5151

52-
status, response = sg.send(message)
52+
response = sg.client.mail.send.post(request_body=message.get())
5353

54-
if status != 200:
55-
return 'An error occurred: {}'.format(response), 500
54+
if response.status_code != 200:
55+
return 'An error occurred: {}'.format(response.body), 500
5656

5757
return 'Email sent.'
5858
# [END example]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Flask==0.11.1
2-
sendgrid==2.2.1
2+
sendgrid==3.0.0
33
gunicorn==19.6.0

0 commit comments

Comments
 (0)