sendgrid-python 客户端适用于一封电子邮件,但不适用于另一封电子邮件
我已经让 Twilio SendGrid 的 Python API 客户端正常工作,并使用一个 from_email
地址发送电子邮件。在新的/不同的应用程序中,我想使用相同的 SendGrid 帐户,但使用不同的 from_email
。我尝试过更改 Mail 类中的 from_email 字段,但这不起作用;我收到以下错误:
Traceback (most recent call last):
...
File "C:\Users\my\path\envs\myproject\lib\site-packages\sendgrid\base_interface.py", line 62, in send
return self.client.mail.send.post(request_body=message)
File "C:\Users\my\path\envs\myproject\lib\site-packages\python_http_client\client.py", line 277, in http_request
self._make_request(opener, request, timeout=timeout)
File "C:\Users\my\path\envs\myproject\lib\site-packages\python_http_client\client.py", line 184, in _make_request
raise exc
python_http_client.exceptions.ForbiddenError: HTTP Error 403: Forbidden
我已确认我的所有代码都适用于旧的 from_email
;唯一的区别是我尝试使用新的 from_email
。
另外,我使用的两个电子邮件地址都是基于 gmail 的电子邮件;一个是 @gmail.com 电子邮件,另一个是自定义业务域,但电子邮件在 gmail 上运行。自定义业务域电子邮件地址是当前正在使用的电子邮件地址。
我的 SendGrid 帐户中是否有需要更改的设置?或者我是否需要为这个新的 from_email
创建一个新的 API 密钥?
I've got Twilio SendGrid's Python API client working and sending emails with one from_email
address. In a new/different application, I want to use the same SendGrid account, but use a different from_email
. I've tried just changing the from_email
field in the Mail
class, but that doesn't work; I get the following error:
Traceback (most recent call last):
...
File "C:\Users\my\path\envs\myproject\lib\site-packages\sendgrid\base_interface.py", line 62, in send
return self.client.mail.send.post(request_body=message)
File "C:\Users\my\path\envs\myproject\lib\site-packages\python_http_client\client.py", line 277, in http_request
self._make_request(opener, request, timeout=timeout)
File "C:\Users\my\path\envs\myproject\lib\site-packages\python_http_client\client.py", line 184, in _make_request
raise exc
python_http_client.exceptions.ForbiddenError: HTTP Error 403: Forbidden
I've confirmed that all of my code works with the old from_email
; the only difference is that the new from_email
I'm trying to use.
Also, both email addresses I'm using are gmail-based emails; One is a @gmail.com email and the other is a custom business domain, but the email is run on gmail. The custom business domain email address is the email address that is currently working.
Is there a setting in my SendGrid account I need to change? Or do I need to create an new API key for this new from_email
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Twilio SendGrid 开发人员布道者在这里。
为了从您的 Gmail 帐户发送电子邮件,您需要验证该电子邮件为发件人,然后您才能从中发送。
电子邮件验证是 SendGrid 了解您拥有该电子邮件的一种方法。但是,域身份验证 ,我假设您已经使用您的域进行了设置,这对于可交付性来说要好得多。即使 SendGrid 知道您拥有 @gmail.com 帐户,Google 也会知道,当您通过 SendGrid 从该地址发送电子邮件时,他们并没有发送该电子邮件,因此您面临着落入垃圾邮件收件箱的风险。但是,为了使您的 API 请求成功,您需要验证电子邮件。
Twilio SendGrid developer evangelist here.
In order to send an email from your gmail account you will need to verify that email as a sender before you can send from it.
Email verification is a method for SendGrid to understand that you own the email. However, domain authentication, which I assume you have set up with your domain, is much better for deliverability. Even when SendGrid knows that you own the @gmail.com account, Google also knows that when you send an email from that address via SendGrid that they didn't send it, so you risk falling into spam inboxes. However, in order to make your API request succeed, you need to verify the email.