SendGrid can now be used in Sakura's cloud, so I tried sending an email from Python. I'm addicted to it, or I've fallen into a part due to lack of google power, so I'll leave a note.
Send an email with Python! Easy to implement with SendGrid|blog| SendGrid
There is also a tutorial on the official website, but it's actually a bit old. Currently, the Sendgrid libraries that you can install with pip are v3 Mail compliant. This is where I'm addicted, and if I google without being aware of this area, I'm stuck in a jar without knowing why it doesn't work. (I'm addicted to it ...)
Documentation>Integrate>Code Examples>v3 Mail>Python How to use v3 of the official documentation. Let's check here first.
Issue your API Key from the Settings section of your Sendgrid dashboard. If you have access to "Mail Send", you can send an email. Make a note of the issued API key.
Preparing the environment on the sending side is very easy.
pip install sendgrid
import sendgrid
import os
from sendgrid.helpers.mail import *
sg = sendgrid.SendGridAPIClient(apikey="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
from_email = Email("[email protected]")
subject = "Hello World from the SendGrid Python Library!"
to_email = Email("[email protected]")
content = Content("text/plain", "Hello, Email!")
mail = Mail(from_email, subject, to_email, content)
response = sg.client.mail.send.post(request_body=mail.get())
print(response.status_code)
print(response.body)
print(response.headers)
Follow the official Tutorial.
Make sure to check the version before using it, and make sure to get official information as well as google (self-advised).
Recommended Posts