我正在使用flask python通过sendgrid发送电子邮件,我按照文档操作,在其中安装pip install sendgrid
并执行了以下操作,但是电子邮件未发送并以状态码202响应,是否有问题我不见了
import sendgrid
from sendgrid.helpers.mail import Email, Content, Mail
def sendEmail():
try:
sg = sendgrid.SendGridAPIClient(apikey="hiddedAPIKey")
from_email = Email("test@example.com")
to_email = Email("myemail@gmail.com")
subject = "Sending with SendGrid is Fun"
content = Content("text/plain", "and easy to do anywhere, even with Python")
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)
except:
print("the was an error")
答案 0 :(得分:1)
您的电子邮件必须转为垃圾邮件。解决这种情况有两种方法
sendgrid
官方documentation,以免电子邮件进入垃圾邮件。