Django:使用 sengrid returns 在电子邮件中添加抄送 HTTP 错误 400:错误请求

Django: adding cc in email with sengrid returns HTTP Error 400: Bad Request

我正在关注 this link 使用 SendGrid 从 Django 发送电子邮件。如果我在 ccto_email 中的电子邮件地址相同,则 returns HTTP 错误 400:错误请求。但如果电子邮件地址不同,它就可以正常工作。以前有人解决过这个问题吗?无论电子邮件地址相同还是不同,我都需要在从 Django 发送电子邮件时添加抄送。提前致谢。

sg = SendGridAPIClient(development.EMAIL_HOST_PASSWORD)
cc_email = str(ImagingCenter.objects.get(institute_id=user.center_id).email)
from_email = development.DEFAULT_FROM_EMAIL
to_email = to_email
data = {
         "personalizations": [{
                        "to": [{
                            "email": to_email
                        }],
                        "cc": [
                            {
                                "email": cc_email
                            }
                        ],
                        "subject": "CC Email Testing"
                    }
                ],
                "from": {
                    "email": from_email
                },
                "content": [
                    {
                        "type": "text/html",
                        "value": html_message
                    }
                ]
            }
            response = sg.client.mail.send.post(request_body=data)

Sendgrid 不允许收件人、抄送和密件抄送字段中存在重复的电子邮件

Sendgrid Personalizations Doc 中也写了:

All of the recipients in a single personalization object (specified in the to, cc, or bcc fields) will see the same email, as defined by the data in that personalization. Because of this, SendGrid does not allow duplicate email addresses among these three recipient arrays in a single personalization.

如果“收件人”和“密件抄送”字段中有相同的电子邮件地址,另请参阅 BadRequest。 #678