By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,898 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,898 IT Pros & Developers. It's quick & easy.

Question about smtplib, and mail servers in general.

P: n/a
Hi. I've been thinking about using smtplib to run a mailing list from my website.

s = smtplib.SMTP("server")
s.sendmail(fromaddress, toaddresess, msg)

I know that in this instance, the toaddresses variable can be a variable
of type list.

Suppose the list contains well over 100 emails. Would that create some
sort of drain on the mail server? Would I be better off doing it in some
other way?

--
www.wintergreen.in

Sep 20 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
On 20/09/05, Chris Dewin <no************@all.com> wrote:

s = smtplib.SMTP("server")
s.sendmail(fromaddress, toaddresess, msg)

I know that in this instance, the toaddresses variable can be a variable
of type list.

Suppose the list contains well over 100 emails. Would that create some
sort of drain on the mail server? Would I be better off doing it in some
other way?
Suppose the list contains well over 100 emails
You mean the list of recipients (toaddresses) ?

The 2 lines of example code send a *single* email to "server" with
len(toaddresses) recipients. The server will then split the email
into smaller (or individual) email groups to send (depending on the
server in use and the mechanisms it uses to relay the email)

You could send a single email for each recipient to "server"
s = smtplib.SMTP("server")
for addr in toaddresses:
s.sendmail(fromaddress,[addr], msg)

# in later revisions, [addr] can be a list, or a string of one address

but that would create much more load on your machine AND server

HTH :)
Sep 20 '05 #2

P: n/a
Chris Dewin wrote:
Hi. I've been thinking about using smtplib to run a mailing list from my website.

s = smtplib.SMTP("server")
s.sendmail(fromaddress, toaddresess, msg)

I know that in this instance, the toaddresses variable can be a variable
of type list.

Suppose the list contains well over 100 emails. Would that create some
sort of drain on the mail server? Would I be better off doing it in some
other way?


Not really an answer to your question, but it's probably considered bad
style to publish the email addresses of the recipients via the address
list. Use a neutral To-address (best: the mailing list address) and add
the recipients via bcc: headers.

You might also want to look at mailman
http://www.gnu.org/software/mailman/, which is a complete mailing list
solution written in Python.

Daniel
Sep 20 '05 #3

P: n/a
On 20/09/05, Daniel Dittmar <da************@sap.corp> wrote:
Chris Dewin wrote:
Hi. I've been thinking about using smtplib to run a mailing list from my website.

s = smtplib.SMTP("server")
s.sendmail(fromaddress, toaddresess, msg)


Not really an answer to your question, but it's probably considered bad
style to publish the email addresses of the recipients via the address
list. Use a neutral To-address (best: the mailing list address) and add
the recipients via bcc: headers.


For clarity

The toaddreses don't show in the email, they are the envelope TO:
addreses. The addresses in the email's TO: Headers are shown to the
recipient and these are the ones that should be "disguised" as best
practice for mailing lists.

The email module's replace_header('to', 'new-text) will do the job for you.
Sep 20 '05 #4

P: n/a
Daniel Dittmar wrote:
Chris Dewin wrote:
Hi. I've been thinking about using smtplib to run a mailing list from
my website.

s = smtplib.SMTP("server")
s.sendmail(fromaddress, toaddresess, msg)

I know that in this instance, the toaddresses variable can be a variable
of type list.

Suppose the list contains well over 100 emails. Would that create some
sort of drain on the mail server? Would I be better off doing it in some
other way?


Not really an answer to your question, but it's probably considered bad
style to publish the email addresses of the recipients via the address
list. Use a neutral To-address (best: the mailing list address) and add
the recipients via bcc: headers.


Not only not an answer, but also not a valid point in this case. The
list of recipients used in the sendmail() call (which become RCPT TO:
commands in SMTP) do *not* show up in the received emails. Only those
items explicitly listed in the headers, such as the To: header, will
appear. In fact, you could easily make a Bcc: header which actually
lists everyone and it would probably not even be stripped by most mail
programs (though I haven't tried that). Your confusion is caused by not
distinguishing between mail client programs and a lower level utility
such as smtplib, which doesn't even look at the To: addresses in the header.

-Peter
Sep 20 '05 #5

P: n/a
Chris Dewin wrote:
Hi. I've been thinking about using smtplib to run a mailing list from my website.

s = smtplib.SMTP("server")
s.sendmail(fromaddress, toaddresess, msg)

I know that in this instance, the toaddresses variable can be a variable
of type list.

Suppose the list contains well over 100 emails. Would that create some
sort of drain on the mail server? Would I be better off doing it in some
other way?


Definitely consider a proper mailing list program like Mailman, as
Daniel suggested.

In any case, unless the mail server will allow "relaying", which most
don't these days (to prevent spamming), then it won't work the way you
are hoping unless *all* the 100 addresses are local ones, to be
delivered to users on the server you are sending the mail to.

If the addresses are scattered all over the planet, and the server
allows relaying, then it's intended for exactly this sort of use (other
than if it's spam ;-) ), and no, you won't be putting a "drain" on the
server.

-Peter
Sep 20 '05 #6

P: n/a
Peter Hansen wrote:
Chris Dewin wrote:
Hi. I've been thinking about using smtplib to run a mailing list from my website.

s = smtplib.SMTP("server")
s.sendmail(fromaddress, toaddresess, msg)

I know that in this instance, the toaddresses variable can be a variable
of type list.

Suppose the list contains well over 100 emails. Would that create some
sort of drain on the mail server? Would I be better off doing it in some
other way?

Definitely consider a proper mailing list program like Mailman, as
Daniel suggested.

In any case, unless the mail server will allow "relaying", which most
don't these days (to prevent spamming), then it won't work the way you
are hoping unless *all* the 100 addresses are local ones, to be
delivered to users on the server you are sending the mail to.

If the addresses are scattered all over the planet, and the server
allows relaying, then it's intended for exactly this sort of use (other
than if it's spam ;-) ), and no, you won't be putting a "drain" on the
server.

-Peter

To add one final note, if the "fromaddress" belongs to a domain that's
properly handled by the SMTP server then you aren't relaying (since you
are a legitimate domain user) so the mails should go through.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.pycon.org

Sep 20 '05 #7

P: n/a
>>>>> Steve Holden <st***@holdenweb.com> (SH) wrote:
SH> To add one final note, if the "fromaddress" belongs to a domain that's
SH> properly handled by the SMTP server then you aren't relaying (since you are
SH> a legitimate domain user) so the mails should go through.


And most smtp servers that I know also pass mail from any from-address to
any to-address if the IP number of he client machine belongs to a trusted
range (usually the range that belongs to the ISP). So I can send both my
private mail and my work mail from both my home ISP's smtp server and my
work's smtp server (but only if I am at the proper location).
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Sep 20 '05 #8

P: n/a
Peter Hansen <pe***@engcorp.com> writes:
Daniel Dittmar wrote:
Chris Dewin wrote:
Hi. I've been thinking about using smtplib to run a mailing list
from my website.

s = smtplib.SMTP("server")
s.sendmail(fromaddress, toaddresess, msg)

I know that in this instance, the toaddresses variable can be a variable
of type list.

Suppose the list contains well over 100 emails. Would that create some
sort of drain on the mail server? Would I be better off doing it in some
other way?

Not really an answer to your question, but it's probably considered
bad style to publish the email addresses of the recipients via the
address list. Use a neutral To-address (best: the mailing list
address) and add the recipients via bcc: headers.


Not only not an answer, but also not a valid point in this case. The
list of recipients used in the sendmail() call (which become RCPT TO:
commands in SMTP) do *not* show up in the received emails.


Not quite. The email address each letter is actually delivered to
generally shows up in one or more Received: headers in the received
email. Some MTAs will add a header (qmail adds Delivered-To:, for
instance) with that same address in it when they deliver the mail
locally. Most MUAs don't display those, but they are there. There may
be an MTA that will pass a single message along to multiple recipients
after adding all of them to one or more headers. I don't know that
such exist - but I wouldn't trust that they don't.

Since you shouldn't trust email to be secure in any case, this isn't a
big deal. Note that using Bcc: doesn't help with this issue - the
addresses a message is delivered to *have* to be in the envelope. Bcc
puts them there and not in the headers.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Sep 20 '05 #9

P: n/a
Steve Holden wrote:
Peter Hansen wrote:
In any case, unless the mail server will allow "relaying", which most
don't these days (to prevent spamming), then it won't work the way you
are hoping unless *all* the 100 addresses are local ones, to be
delivered to users on the server you are sending the mail to.

If the addresses are scattered all over the planet, and the server
allows relaying, then it's intended for exactly this sort of use
(other than if it's spam ;-) ), and no, you won't be putting a "drain"
on the server.


To add one final note, if the "fromaddress" belongs to a domain that's
properly handled by the SMTP server then you aren't relaying (since you
are a legitimate domain user) so the mails should go through.


I think that statement might not be widely valid any more, Steve. In my
experience, lately, many if not most servers pay no attention to the
"MAIL FROM" address but instead allow relaying only from *IP addresses*
on the "internal" network (e.g. those served by an ISP, for example),
regardless of how the sender is identified. On a Linux box with Qmail,
for example, one would have an /etc/tcp.smtp file which specifies for
which subnets relaying is allowed, and all others are disallowed
regardless of the claimed MAIL FROM address.

It's kind of a shame, really, that you can no longer trust either the
recipient *or* the sender addresses when using basic SMTP. Damn spammers.

-Peter
Sep 21 '05 #10

P: n/a
Peter Hansen wrote:
Steve Holden wrote:
Peter Hansen wrote:
In any case, unless the mail server will allow "relaying", which most
don't these days (to prevent spamming), then it won't work the way you
are hoping unless *all* the 100 addresses are local ones, to be
delivered to users on the server you are sending the mail to.

If the addresses are scattered all over the planet, and the server
allows relaying, then it's intended for exactly this sort of use
(other than if it's spam ;-) ), and no, you won't be putting a "drain"
on the server.


To add one final note, if the "fromaddress" belongs to a domain that's
properly handled by the SMTP server then you aren't relaying (since you
are a legitimate domain user) so the mails should go through.

I think that statement might not be widely valid any more, Steve. In my
experience, lately, many if not most servers pay no attention to the
"MAIL FROM" address but instead allow relaying only from *IP addresses*
on the "internal" network (e.g. those served by an ISP, for example),
regardless of how the sender is identified. On a Linux box with Qmail,
for example, one would have an /etc/tcp.smtp file which specifies for
which subnets relaying is allowed, and all others are disallowed
regardless of the claimed MAIL FROM address.

It's kind of a shame, really, that you can no longer trust either the
recipient *or* the sender addresses when using basic SMTP. Damn spammers.

I agree that there's an element of the moral imperative in my assertion
that the mails "should" go through which is largely ignored by the real
world nowadays. Some ISPs force you to use their SMTP servers no matter
what the sending domain, which is rather annoying when you travel a lot.
I end up having to vary my default SMTP server as I move.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.pycon.org

Sep 21 '05 #11

P: n/a
On Tue, 20 Sep 2005 16:48:41 +0200, rumours say that Piet van Oostrum
<pi**@cs.uu.nl> might have written:
And most smtp servers that I know also pass mail from any from-address to
any to-address if the IP number of he client machine belongs to a trusted
range (usually the range that belongs to the ISP). So I can send both my
private mail and my work mail from both my home ISP's smtp server and my
work's smtp server (but only if I am at the proper location).


You might start having troubles, though, as soon as SPF checks get more
widespread.

Say your work mail is pi**@example.com, and your private mail is
pi**@yagoohoogle.com; if you send email through your office mail server
with the envelope "MAIL FROM: pi**@yagoohoogle.com\n", then some (and
eventually many) receiving servers shall ask yagoohoogle.com for their
SPF record, and since your office mail server won't probably show up as
a valid email sender from yagoohoogle.com , your email will get
rejected.

That's a good thing.
--
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
Sep 26 '05 #12

P: n/a
On Wed, 21 Sep 2005 07:50:26 +0100, rumours say that Steve Holden
<st***@holdenweb.com> might have written:
I agree that there's an element of the moral imperative in my assertion
that the mails "should" go through which is largely ignored by the real
world nowadays. Some ISPs force you to use their SMTP servers no matter
what the sending domain, which is rather annoying when you travel a lot.
I end up having to vary my default SMTP server as I move.


....or set up your email client to always connect to localhost ports eg
31025 and 31110, and then from wherever you are, you connect to an SSH
server trusted by your "standard" mail server and port-forward to it.

Don't know if this applies to your case, but it works for me :)
--
Christos Georgiou, Customer Support Engineer
Silicon Solutions, Medicon Ltd.
Melitonos 5, Gerakas 153 44 Greece
Tel +30 21 06606195 Fax +30 21 06606599 Mob +30 693 6606195
"Dave always exaggerated." --HAL
Sep 26 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.