美文网首页
(Python)使用sendgrid服务

(Python)使用sendgrid服务

作者: 西厌西厌 | 来源:发表于2020-07-24 11:40 被阅读0次

资料

使用步骤

1. 注册账号,根据提示注册api key,或者在左下角点击API Keys
2. python示例
   ak = 'API Keys页面创建'
   domain = 'test.com'
   message = Mail(
        from_email='support@' + domain,
        to_emails=email,
        subject='Check your verify code from Test',
        html_content='Your verify code is <strong>'+str(code)+'</strong>( within five minutes ),do not reply this Email!')
    status = 0
    try:
        sg = SendGridAPIClient(ak)
        response = sg.send(message)
        print("code")
        status = response.status_code

        print(status)
        print(response)
    except Exception as e:
        print(e)

排抗

1. 遇到163邮箱无法收到的问题,解决方式为设置spf

a. 在sendgrid官网左下角,点击Sender Authentication,复制Link Branding下,STATUS为Verifed的DOMAIN
b. 将此DOMAIN放到域名服务商,以godaddy为例
# dns下添加TXT
v=spf1 include:复制的domain ~all

相关文章

网友评论

      本文标题:(Python)使用sendgrid服务

      本文链接:https://www.haomeiwen.com/subject/wprjlktx.html