elbuo8 / sendgrid-django

Simple django backend to send email through SendGrid
MIT License
207 stars 78 forks source link

EmailMultiAlternatives bcc not working #59

Open sandeepsayone opened 7 years ago

sandeepsayone commented 7 years ago

Giving bcc attribute is giving error

mail = EmailMultiAlternatives(subject="Your Subject", body="This is a simple text email body.", from_email="Yamil Asusta <hello@yamilasusta.com>", to=["yamil@sendgrid.com"], bcc=["yamil@sendgrid.com"])
mail.send()
python_http_client/client.py", line 161, in _make_request
    raise exc
BadRequestsError
sklarsa commented 7 years ago

I'm actually getting the same error when passing in additional headers to the EmailMultiAlternatives constructor like so: headers={"Reply-To": "my-email-address@domain.com"}.

I wish I could get more debugging information from the exception itself but it looks it's being raised incorrectly in python_http_client, (line 161 should just be raise to preserve the stack trace).

I'm going to dig into this more to see if I can discover what's going on

sklarsa commented 7 years ago

I actually ended up creating a new repo (https://github.com/sklarsa/django-sendgrid-v4) to support the sendgrid-python v4.0+ library. It should be compatible with both the EmailMessage and EmailMultiAlternatives django classes, and I'm currently writing out the test suite to guarantee that.

Unfortunately, it looks like this library isn't being maintained on a regular basis, seeing as how PR #58 is accepted(yet still open), and @pcraciunoiu has been left hanging on PR #55, which is a pretty critical PR that deals with breaking changes.

I don't like the idea of creating a new library for basically the same thing, but I am in need of a working sendgrid/django backend for my app. I'd like to hit other unaddressed issues from this repo as well (such as successfully sending emails with embedded images). I'd be happy to accept any help (including Issues and PRs), and am also very open to working with sendgrid and/or the maintainer of this repo to keep this functionality alive.

andriisoldatenko commented 7 years ago
b'{"errors":[{"message":"Each email address in the personalization block should be unique between to, cc, and bcc. We found the first duplicate instance of [andrii.soldatenko@gmail.com] in the personalizations.0.bcc field.","field":"personalizations.0","help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.recipient-errors"}]}'
andriisoldatenko commented 7 years ago

@sandeepsayone please take a look.

sandeepsayone commented 7 years ago

@andriisoldatenko thanks. Issues seems to be with to and bcc. I tried with unique emails in to and bcc and it worked. But not working when the to list is empty. I wanted to send emails to many email addresses without each of them knowing who else got the message (bcc) and don't want to give to email address.