I am new to Python. I have a case where I need to send email where the Bcc:
list must be populated and To:
list must be blank in order to hide the recipients identity.
I gave msg['TO']
as ''
, None
, ['']
, []
. None of these worked.
I Googled, but found nothing related to my problem. I kept To:
list blank in my code and some email ids in Bcc:
list, then ran my code and got the following error:
Traceback (most recent call last):
File "C:\Users\script.py", line 453, in send_notification
smtp.sendmail(send_from, send_to, msg.as_string())
File "C:\Python27\lib\smtplib.py", line 742, in sendmail
raise SMTPRecipientsRefused(senderrs)
SMTPRecipientsRefused: {'': (555, '5.5.2 Syntax error. hb1sm19555493pbd.36 - gsmtp')}
Following is my code:
msg['From'] = send_from
msg['To'] = ''
msg['Subject'] = subject
msg['BCC'] = COMMASPACE.join(send_to)