Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bcc does not work in latest versions #83

Closed
mehernosh opened this issue Sep 4, 2014 · 15 comments
Closed

bcc does not work in latest versions #83

mehernosh opened this issue Sep 4, 2014 · 15 comments

Comments

@mehernosh
Copy link

I'm using the add_bcc method to specify a bcc list.

When I first installed it the version was 0.5.4
Everything was working fine till I updated to the latest version 1.1.0. After updating the bcc functionality stopped working. The emails were still being delivered to the addresses specified in the "to" field but nothing is delivered to the "bcc" addresses.

I checked and can reproduce this problem in 1.0.1 too.

(I've fixed the issue temporarily by rolling back to 0.5.4)
Thanks

@jshirley
Copy link

jshirley commented Sep 4, 2014

Are you doing something that is triggering usage of the X-SMTP API? I just ran across this and found sendgrid/sendgrid-php#23

X-SMTP doesn't support BCC it seems, since each to is a separate and unique email. This is a bummer :(

Still trying to find a workaround!

@philnelson
Copy link

Same problem. Would be nice if this were at least documented, because it's caused us some trouble.

@suhaasprasad
Copy link

Likewise, haven't found a solution for this

@elbuo8
Copy link
Contributor

elbuo8 commented Oct 21, 2014

For a workaround, use

mail.to = ['email1', 'email2']
mail.bcc = ['email1', 'email2']

I will update the add_to method in the library to default to regular 'To' parameter instead of the SMTPAPI (which can't use BCC unless its the BCC filter).

@elbuo8
Copy link
Contributor

elbuo8 commented Oct 21, 2014

Hey, I have pushed a new release which is very specific.

c015885

In order to use the SMTPAPI header, you need to explicitly say so instead of the add_to method defaulting to it. Wrapper methods were created in order to be backwards compatible with the other SMTPAPI methods (subs, filters etc).

Let me know if this works for all of you :)

@suhaasprasad
Copy link

@elbuo8 Thanks for the workaround. I tried out the first approach, but it's not great because the address that I'm trying to bcc is unable to see who the original email was intended for if it just gets sent via the "to" field.

I haven't tried using your new commit, but I'm guessing it would work similarly given the add_to method. Should I assume that the smtpapi bcc filter is the only way to do this then?

@elbuo8
Copy link
Contributor

elbuo8 commented Oct 22, 2014

@suhaasprasad the new version add_to method will behave the way you are expecting it to behave :)

If you use the bcc filter, the BCC recipient will not be able to see the To recipients.

@elbuo8 elbuo8 closed this as completed Oct 27, 2014
@AngeloK
Copy link

AngeloK commented Mar 3, 2016

@suhaasprasad did you figure this out finally? I am meeting the exactly same problem now.

@sachin2811
Copy link

sachin2811 commented May 29, 2018

import sendgrid
from sendgrid.helpers.mail import *
import traceback
import urllib
from sendgrid.helpers.mail import Mail, Email, Content

class SendMail():
def send_mail(self, to_email, from_email, subject, message, bcc, cc, name):
try:
print(cc)
sg = sendgrid.SendGridAPIClient(apikey='XXXX')
From_Email = Email(from_email,name)
To_Email = Email(to_email)
Subject = subject
content = Content("text/html", message)
mail = Mail(From_Email, Subject, To_Email, content)
personalization = Personalization()
mail_list_cc = []
mail_list_bcc = []
mail_list_bcc.append(bcc)
mail_list_cc.append(cc)
personalization.add_bcc(Email(bcc))
personalization.add_cc(Email(cc))
mail.add_personalization(personalization)
print(mail.get())
response = sg.client.mail.send.post(request_body=mail.get())
print(response)
except Exception as error:
print('Exception in send_mail...' + str(error))
print(traceback.format_exc().splitlines())

if name == 'main':
sm = SendMail()
sm.send_mail(''xyz@gmail.com'',''xyz@gmail.com'', 'Testing_Sendgrid','Hey this is xyz from XYZ', ''xyz@gmail.com' ',''xyz@gmail.com'','qwerty')

and my mail.get() is:

{'subject': 'Testing_Sendgrid', 'from': {'email': ''xyz@gmail.com'', 'name': 'qwerty'}, 'personalizations': [{'to': [{'email': ''xyz@gmail.com''}]}, {'bcc': [{'email': ''xyz@gmail.com''}], 'cc': [{'email': 'xyz@gmail.com'}]}], 'content': [{'value': 'Hey this is sagar from digicollect', 'type': 'text/html'}]}

and i get this error

HTTP Error 400: Bad Request

can someone guide me through this

@thinkingserious
Copy link
Contributor

Hello @sachin2811,

Can you please extract the error message like so? Thanks!

With Best Regards,

Elmer

@sachin2811
Copy link

Hey @thinkingserious thanks for your reply,
sm.send_mail(''xyz@gmail.com,''xyz@gmail.com', 'Testing_Sendgrid','Hey this is xyz from xyz', ''xyz@gmail.com ','xyz@gmail.com','xyz xyz')
File "sendmail.py", line 36, in send_mail
response = sg.client.mail.send.post(request_body=mail.get())
/email_server/emailserver/lib/python3.5/site-packages/python_http_client/client.py", line 227, in http_request
return Response(self._make_request(opener, request))
/email_server/emailserver/lib/python3.5/site-packages/python_http_client/client.py", line 161, in _make_request
raise exc
python_http_client.exceptions.BadRequestsError: HTTP Error 400: Bad Request

I get this

@thinkingserious
Copy link
Contributor

Hello @sachin2811,

What is the value of response.body?

@sachin2811
Copy link

It doesn't happen that way since it does not return anything. It says bad request 400

@thinkingserious
Copy link
Contributor

Hello @sachin2811,

I think I've discovered what happened. When you call the mail = Mail(From_Email, Subject, To_Email, content) constructor, it creates a personalization object behind the scenes for you. To add to it, you would do personalization[0].add_bcc(Email(bcc)). Otherwise, you could call Mail() without any parameters like so.

I hope that helps!

With Best Regards,

Elmer

@sachin2811
Copy link

Hi @thinkingserious .Figured it, did whatever your mentioned and its fine now.Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants