I am following this link to send emails from Django using SendGrid. If my email address in cc and to_email is same, it returns HTTP Error 400: Bad Request. But it works fine if the email address is different. Did anyone solve this problem before? I need to add cc while sending an email from Django whether the email address is the same or different. Thanks in advance.
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 does not allow for duplicate emails among the to, cc and bcc fields.
That is also wrote in 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.
See also BadRequest if same email address is in the To & BCC fields. #678