Bcc field in SMTP [showing / not showing] problem

I am trying to use python smtplib to send gmail emails with address addresses. I am using this code:

#imports etc... fromAddr = sender@origin.com to = [ recpt1@destinationTo.com ] cc = [ recpt2@destinationCc.com ] bcc = [ recpt3@destinationBcc.com , recpt4@destinationBcc.com ] server = SMTP( "smtp.gmail.com", 587) #starttls, login, etc.. content = "Hello, this is a message." msg = "From: %s\r\nTo:%s\r\nCc: %s\r\n\r\n%s" % ( from, to, cc, content ) server.sendmail( fromAddr, to + cc + bcc, msg ) #server.quit() etc... 

-> When I go to the corresponding Inbox, I get the same message for all addresses in [to + cc + bcc], which is correct. But

what I would like to do was that each bcc address received a Bcc field with its own address in it, as described in here for the gmail web interface.

This is what I want to accomplish:

Cc and In Inboxes:

 To: recpt1@destinationTo.com From: sender@origin.com Cc: recpt2@destinationCc.com (...) 

recpt3 Inbox:

 To: recpt1@destinationTo.com From: sender@origin.com Cc: recpt2@destinationCc.com Bcc: recpt3@destinationBcc.com (...) 

recpt4 Inbox:

 To: recpt1@destinationTo.com From: sender@origin.com Cc: recpt2@destinationCc.com Bcc: recpt4@destinationBcc.com (...) 

Has anyone managed to get this to work? I am looking at smtp rfc docs and haven’t found anything, I don’t understand how to do gmail

+4
source share
1 answer

I assume gmail has a separate SMTP session for each BCC recipient. If all that was between your two comments was the dosend(fromAddr, toAddr, content, to, cc, bcc=None) function dosend(fromAddr, toAddr, content, to, cc, bcc=None) , you could do something like this:

 dosend(fromAddr, to+cc, content, to, cc) for t in bcc: dosend(fromAddr, t, content, to, cc, t) 

This will send it once to the to and cc addresses, and then send them again to each bcc address individually with the corresponding control panel header. To clarify what dosend is: the fromAddr and toAddr refer to the envelope (the first and second server.sendmail arguments). The arguments to , cc and (optionally) bcc for headers in msg . (Your code does not add Bcc, you need to add this if the optional bcc argument is provided.)

(Edit: I deleted my comments about the possibility of using X-Bcc. I just tried it and it works as described above. I also corrected and refined the description of dosend .)

+1
source

All Articles