473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 14646

[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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dmiller23462 | last post by:
So here's my problem.....I need to set up different email distributions based on which option in the following Select form has been chosen....For instance if "Putaway" is chosen it needs to email...
1
by: james00_c | last post by:
Greetings- I need to pass multiple email addresses to a "sendto" hidden field in a form. I need to do that because "CC" and "BCC" are not an option. One address webmaster@xyz.com would be...
1
by: eight02645999 | last post by:
hi i currently am using this email function that can send single email address def email(HOST,FROM,TO,SUBJECT,BODY,CC=None): import smtplib import string, sys body = string.join(( "From: %s" %...
1
by: TCB | last post by:
How can I separate multiple email addresses entered in a single textbox, the email addresses are separated by (,) or (;) Thanks
1
by: donet programmer | last post by:
Is there a way to map multiple email addresses, for instance emailadd1@domain.com, emailadd2@domain.com.. etc to one email address emailadd@domain.com such that when an email is sent to emailadd1...
0
by: krouxsa | last post by:
Hi There people... Please help me with this query. I want to send 1 email to multiple email addresses stored in a database. Will it be possible? I'm using SQL Server 2005 and already set up...
15
pradeepjain
by: pradeepjain | last post by:
how to write javascript or is there any javascript fot validating multiple email id's ....ex xx@abc.com,yy@bbc.com Thanks, Pradeep
6
by: alfasol | last post by:
I have a search module which has a search form and a php script to search. Now i have to use this search module over multiple sites . If i do that it shows path of search script on browser than the...
8
n8kindt
by: n8kindt | last post by:
i have a function created for simple emailing (posted below). i'm new to arrays. i actually figured out how to set up the last value (Att) as an array so i could add an unlimited amount of...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.