On Aug 5, 12:18 am, Tim Roberts <[EMAIL PROTECTED]> wrote: > >But when using smtp.gmail.com as the server I learned that any > >@gmail.com address in the Cc: text block would > >receive mail even if I changed the code to have the RECEIVERS list to > >ignore the CC addresses or not include the gmail address in the CC > >list as below > > Interesting. If true, that is incorrect behavior.
I ran some more tests and now I am pretty sure session.sendmail(SENDER, RECEIVERS, BODY) is only sending to the RECEIVERS list, ignoring the Cc: field in the body (as it should) What fooled me is that I was using my own gmail account (i.e., [EMAIL PROTECTED]) as a Cc: field and not putting it in the RECEIVERS list. It seems Gmail creates two links (or copies?) to the message: (1) as it is stored in the SENT box (as it should since the message was sent by my gmail account) and (2) another in my INBOX because the mail reading software reads the Cc: field. Other smtp servers such as comcast do not create the stored SENT mail and hence behave different in terms of how they treat Cc: fields of the same account ([EMAIL PROTECTED] in this case). Most important, using another gmail account (not [EMAIL PROTECTED]) as a Cc: field does not create another sent message (outside of what is in the RECEIVERS field). Sorry for confusion, and I do appreciate the tips as I now see how almost anything To:, Cc:, Bcc: combination can be handled by a proper RECEIVERS list. Below is python code that can be used by anyone that wants to test what I did (just fill in the SMTPuser and password variables) and then check you gmail inbox import sys, os, glob, datetime, time import smtplib ## Parameters for SMTP session port=587 SMTPserver= 'smtp.gmail.com' SMTPuser= '[EMAIL PROTECTED]' pw= 'fill in here' SENDER= SMTPuser ## Message details FROM= SENDER TO= '[EMAIL PROTECTED]' CC=FROM ##RECEIVERS= (TO, CC) ##proper way to send to both TO and CC RECEIVERS= (TO,) ## ignore the CC address subject= 'Test 1a' message='*** Email test *** ' print 'Starting SMTP mail session on %s as %s ' % (SMTPserver,SMTPuser) session = smtplib.SMTP(SMTPserver,port) session.set_debuglevel(0) # set debug level to 1 to see details session.ehlo(SMTPuser) # say hello session.starttls() # TLS needed session.ehlo(SMTPuser) # say hello again, not sure why session.login(SMTPuser, pw) ##Create HEADER + MESSAGE HEADER= 'From: %s\r\n' % FROM HEADER= HEADER + 'To: %s\r\n' % TO HEADER= HEADER + 'Cc: %s\r\n' % CC HEADER= HEADER + 'Subject: %s\r\n' % subject BODY= HEADER + '\r\n' + message print BODY SMTPresult = session.sendmail(SENDER, RECEIVERS, BODY) ## send email session.close() -- http://mail.python.org/mailman/listinfo/python-list