이 라이브러리를 사용하면 Python을 통해 SendGrid Web API v3을 빠르고 쉽게 사용할 수 있습니다.
이 라이브러리의 버전 3.X.X+는 새로운 v3 /mail/send를 포함하여 모든 SendGrid Web API v3 엔드포인트를 완벽하게 지원합니다.
이 라이브러리는 SendGrid에 대한 새로운 경로의 시작을 나타냅니다. 우리는 이 라이브러리가 커뮤니티 중심으로 SendGrid가 주도하기를 원합니다. 이 목표를 실현하려면 여러분의 도움이 필요합니다. 올바른 순서에 따라 올바른 항목을 구축할 수 있도록 이슈 및 끌어오기 요청을 생성하거나 기존 문제 또는 끌어오기 요청에 찬성표를 달거나 의견을 제시해 주시기 바랍니다.
SendGrid 사용에 도움이 필요하면 Twilio SendGrid 지원 도움말 센터를 확인하세요.
자세한 내용은 이 README의 나머지 부분을 살펴보세요.
SENDGRID_API_KEY(자세한 내용은 여기)를 사용하여 개발 환경을 업데이트하세요. 예를 들면 다음과 같습니다.
echo " export SENDGRID_API_KEY='YOUR_API_KEY' " > sendgrid.env
echo " sendgrid.env " >> .gitignore
source ./sendgrid.env
SendGrid는 로컬 환경 파일 .env
도 지원합니다. .env_sample
.env
로 복사하거나 이름을 바꾸고 SENDGRID_API_KEY를 키로 업데이트하세요.
환경 변수를 임시로 설정합니다(현재 cli 세션 중에만 액세스 가능).
set SENDGRID_API_KEY=YOUR_API_KEY
환경 변수를 영구적으로 설정합니다(모든 후속 CLI 세션에서 액세스 가능).
setx SENDGRID_API_KEY " YOUR_API_KEY "
pip install sendgrid
다음은 /mail/send 도우미를 사용하여 이메일을 보내는 데 필요한 최소 코드입니다(전체 예는 다음과 같습니다).
import sendgrid
import os
from sendgrid . helpers . mail import *
sg = sendgrid . SendGridAPIClient ( api_key = os . environ . get ( 'SENDGRID_API_KEY' ))
from_email = Email ( "[email protected]" )
to_email = To ( "[email protected]" )
subject = "Sending with SendGrid is Fun"
content = Content ( "text/plain" , "and easy to do anywhere, even with Python" )
mail = Mail ( from_email , to_email , subject , content )
response = sg . client . mail . send . post ( request_body = mail . get ())
print ( response . status_code )
print ( response . body )
print ( response . headers )
Mail
생성자는 사용자를 위한 개인화 개체를 생성합니다. 추가하는 방법의 예는 다음과 같습니다.
다음은 /mail/send 도우미 없이 이메일을 보내는 데 필요한 최소 코드입니다(전체 예는 다음과 같습니다).
import sendgrid
import os
sg = sendgrid . SendGridAPIClient ( api_key = os . environ . get ( 'SENDGRID_API_KEY' ))
data = {
"personalizations" : [
{
"to" : [
{
"email" : "[email protected]"
}
],
"subject" : "Sending with SendGrid is Fun"
}
],
"from" : {
"email" : "[email protected]"
},
"content" : [
{
"type" : "text/plain" ,
"value" : "and easy to do anywhere, even with Python"
}
]
}
response = sg . client . mail . send . post ( request_body = data )
print ( response . status_code )
print ( response . body )
print ( response . headers )
import sendgrid
import os
sg = sendgrid . SendGridAPIClient ( api_key = os . environ . get ( 'SENDGRID_API_KEY' ))
response = sg . client . suppression . bounces . get ()
print ( response . status_code )
print ( response . body )
print ( response . headers )
import sendgrid
import os
sg = sendgrid . SendGridAPIClient ( api_key = os . environ . get ( 'SENDGRID_API_KEY' ))
response = sg . client . _ ( "suppression/bounces" ). get ()
print ( response . status_code )
print ( response . body )
print ( response . headers )
인바운드 구문 분석 웹훅을 활용하려면 도우미를 참조하세요.
트랜잭션 템플릿을 사용하여 이메일을 보내는 방법과 같은 일반적인 API 사용 사례의 예입니다.
이 라이브러리에 대한 모든 업데이트는 CHANGELOG 및 릴리스에 문서화되어 있습니다.
우리는 우리 도서관에 대한 기여를 장려합니다(멋진 장식을 얻을 수도 있습니다). 자세한 내용은 CONTRIBUTING 가이드를 참조하세요.
빠른 링크:
일반적인 라이브러리 문제에 대해서는 문제 해결 가이드를 참조하세요.
sendgrid-python은 Twilio SendGrid, Inc.에서 유지 관리하고 자금을 지원합니다. sendgrid-python의 이름과 로고는 Twilio SendGrid, Inc.의 상표입니다.
지원이 필요한 경우 Twilio SendGrid 지원 도움말 센터를 확인하세요.
MIT 라이센스 (MIT)