Sendgrid不发送电子邮件

时间:2019-03-07 09:36:41

标签: python sendgrid

我正在使用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")

1 个答案:

答案 0 :(得分:1)

您的电子邮件必须转为垃圾邮件。解决这种情况有两种方法

  • 您可以进入垃圾邮件文件夹,然后单击发自电子邮件地址作为受信任的电子邮件地址。 (对于多个发件人地址无效)
  • 检查sendgrid官方documentation,以免电子邮件进入垃圾邮件。