SMTP via GMAIL

mmm mdboldin at gmail.com
Sat Aug 2 17:36:54 EDT 2008


After reading about and using the smtplib module, I thought code such
as below would ignore the 'Cc: ' body line below when sending messages
and instead simply use the RECEIVERS list

session = smtplib.SMTP(SMTPserver,port)
session.set_debuglevel(1)
session.ehlo(SMTPuser)  # say hello
session.starttls()  # TLS needed
session.ehlo(SMTPuser)  # say hello again
session.login(SMTPuser, pw)

FROM=SENDER
RECEIVERS= (TO,CC)

BODY= MakeBody(FROM,TO,CC,SUBJECT,MESSAGE)
SMTPresult = session.sendmail(SENDER, RECEIVERS, BODY)

Here the MakeBody() creates text like below

From: FROM
To: TO
Cc: CC
Subject: SUBJECT

MESSAGE

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

RECEIVERS= (TO,)
BODY= MakeBody(FROM,TO,CC,subject,message)
SMTPresult = session.sendmail(SENDER, RECEIVERS, BODY)

Other @zzz.com CC addresses need to be in the RECEIVERS list however.

Also the gmail server changes the  'From:  '  text to be the same as
SENDER even if this is modified (a case not using FROM=SENDER.  I
found other servers send mail that  displays the BODY specified From:
address.

Is this gmail specific or a quirk of the smtplib functions?
I understand how Google might not want to send mail with FROM not =
SENDER, but the CC behavior baffles me.

And does anyone have a general routine that lets one also have Bcc:
addresses usign SMTP?





More information about the Python-list mailing list