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(SM TPserver,port)
session.set_deb uglevel(1)
session.ehlo(SM TPuser) # say hello
session.starttl s() # TLS needed
session.ehlo(SM TPuser) # say hello again
session.login(S MTPuser, pw)
FROM=SENDER
RECEIVERS= (TO,CC)
BODY= MakeBody(FROM,T O,CC,SUBJECT,ME SSAGE)
SMTPresult = session.sendmai l(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,T O,CC,subject,me ssage)
SMTPresult = session.sendmai l(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?
as below would ignore the 'Cc: ' body line below when sending messages
and instead simply use the RECEIVERS list
session = smtplib.SMTP(SM TPserver,port)
session.set_deb uglevel(1)
session.ehlo(SM TPuser) # say hello
session.starttl s() # TLS needed
session.ehlo(SM TPuser) # say hello again
session.login(S MTPuser, pw)
FROM=SENDER
RECEIVERS= (TO,CC)
BODY= MakeBody(FROM,T O,CC,SUBJECT,ME SSAGE)
SMTPresult = session.sendmai l(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,T O,CC,subject,me ssage)
SMTPresult = session.sendmai l(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?
Comment