I tried sending an email with SendGrid + Python

is.PNG

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. キャプチャ.PNG 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

I tried sending an email with SendGrid + Python
I tried sending an email with python.
I tried sending an email from Amazon SES with Python
I tried sending an SMS with Twilio
I tried sending an email from the Sakura server with flask-mail
I tried scraping with Python
I tried gRPC with Python
I tried scraping with python
I tried web scraping with python.
I sent an SMS with Python
Easy email sending with haste python3
I tried running prolog with python 3.8.2.
[Python] Send an email with outlook
I tried SMTP communication with Python
I tried scraping Yahoo News with Python
I tried non-photorealistic rendering with Python + opencv
I tried a functional language with Python
I tried recursion with Python ② (Fibonacci sequence)
Send an email with Amazon SES + Python
#I tried something like Vlookup with Python # 2
I tried to make an image similarity function with Python + OpenCV
I tried "smoothing" the image with Python + OpenCV
I tried hundreds of millions of SQLite with python
I tried "differentiating" the image with Python + OpenCV
Send an email to Spushi's address with python
I tried Python> autopep8
I tried L-Chika with Raspberry Pi 4 (Python edition)
I tried Jacobian and partial differential with python
I tried to get CloudWatch data with Python
I tried function synthesis and curry with python
I tried to output LLVM IR with Python
I tried "binarizing" the image with Python + OpenCV
I tried running faiss with python, Go, Rust
I tried to detect an object with M2Det!
I tried to automate sushi making with python
I tried playing mahjong with Python (single mahjong edition)
Validate E-Mail with Python
[Outlook] I tried to automatically create a daily report email with Python
I tried running Deep Floor Plan with Python 3.6.10.
Send email with Python
I tried Python> decorator
Send an email with Excel attached in Python
I tried to make a simple mail sending application with tkinter of Python
I tried to implement Minesweeper on terminal with python
I tried to touch the CSV file with Python
I tried to draw a route map with Python
[OpenCV / Python] I tried image analysis of cells with OpenCV
I tried to solve the soma cube with python
I tried Smith standardizing an integer matrix with Numpy
I tried to get started with blender python script_Part 02
I tried to automatically generate a password with Python3
Mayungo's Python Learning Episode 1: I tried printing with print
I tried to solve the problem with Python Vol.1
I tried to analyze J League data with Python
I tried to make an OCR application with PySimpleGUI
Python: I tried a liar and an honest tribe
I tried to find an alternating series with tensorflow
I tried "morphology conversion" of images with Python + OpenCV
I tried hitting the API with echonest's python client
I tried to solve AOJ's number theory with Python
Send Japanese email with Python3