469,925 Members | 1,578 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,925 developers. It's quick & easy.

smtp module - specifying multiple email recipients?

I'm using the smtp module to send emails from python.
I would like to specify several recipients of the email like follows:

msg = MIMEText(time.ctime("Body text of email")

me = 'm*@sending.address'
you = 'r*********@some.where,re********@some.where'
msg['Subject'] = '*** Carwatch alert'
msg['From'] = me
msg['To'] = you

# Send the message via our own SMTP server, but don't include the
# envelope header.
# s = smtplib.SMTP('smtp.ednet.co.uk')
s = smtplib.SMTP('192.168.1.105')
# s.connect()
s.sendmail(me, [you], msg.as_string())

... when I execute this code, only re********@some.where gets the email.
Is there a way to specifiy multiple addresses in the To field?

thanks
alex

Jul 18 '05 #1
2 14426

[Alex]
I would like to specify several recipients of the email like follows:

you = 'r*********@some.where,re********@some.where'
...
msg['To'] = you
...
s.sendmail(me, [you], msg.as_string())

.. when I execute this code, only re********@some.where gets the email.


sendmail() takes a list of recipients, not a list with a single
comma-separated string in it. You need to do this:

you = ['r*********@some.where', 're********@some.where']
...
msg['To'] = ', '.join(you)
...
s.sendmail(me, you, msg.as_string())

--
Richie Hindle
ri****@entrian.com
Jul 18 '05 #2
In article <10*************@corp.supernews.com>, Alex Hunsley wrote:
I'm using the smtp module to send emails from python. me = 'm*@sending.address'
you = 'r*********@some.where,re********@some.where' s.sendmail(me, [you], msg.as_string())

.. when I execute this code, only re********@some.where gets the email.
Is there a way to specifiy multiple addresses in the To field?


The second argument to sendmail is a list, not a comma separated string.
Currently, you've specified a single address containing a comma. Your
MTA has charitably decided to deliver it to the first address, although
I expect other MTAs would just reject it. If you've got comma separated
addresses in a string, make a list using s.split(",").

--
Paul Wright | http://pobox.com/~pw201 | http://blog.noctua.org.uk/
Reply address is valid but discards mail with attachments: send plain text only
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by eight02645999 | last post: by
1 post views Thread by TCB | last post: by
1 post views Thread by donet programmer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.