(Python)使用sendgrid服务

2020-07-24  本文已影响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
上一篇下一篇

猜你喜欢

热点阅读