dolfim / django-gmailapi-backend

Email backend for Django which sends email via the Gmail API
Apache License 2.0
32 stars 9 forks source link

Bcc not working #7

Closed rfreis closed 2 years ago

rfreis commented 3 years ago

Hi guys! How are you doing?

First of all, congratulations for your job with this package! It has been really helpful using it!

While sending emails, I realized that Django's EmailMessage doesn't attach the bcc recipient's to the message, and it instead uses separately the recipients() which works good with other backends like smtp.

To workaround that, I made a small change on GmailBackend.send_message. If you find useful, I can open a new pull request to update the package

Thanks Rodrigo

class GmailBackendWithBcc(GmailBackend):
    def send_message(self, email_message):
        if not email_message.recipients():
            return False
        message = email_message.message()
        if email_message.bcc:
            email_message._set_list_header_if_not_empty(message, 'Bcc', email_message.bcc)
        raw_message = {'raw': base64.urlsafe_b64encode(message.as_bytes()).decode()}
        return self.service.users().messages().send(userId=self.user_id, body=raw_message)
dolfim commented 2 years ago

Solved in #12. Thanks for the contribution.