Question about smtplib, and mail servers in general.

C

Chris Dewin

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?
 
T

Tim Williams (gmail)

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 :)
 
D

Daniel Dittmar

Chris said:
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
 
T

Tim Williams (gmail)

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.
 
P

Peter Hansen

Daniel said:
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
 
P

Peter Hansen

Chris said:
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
 
S

Steve Holden

Peter said:
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
 
P

Piet van Oostrum

Steve Holden said:
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).
 
M

Mike Meyer

Peter Hansen said:
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
 
P

Peter Hansen

Steve said:
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
 
S

Steve Holden

Peter said:
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
 
C

Christos Georgiou

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 (e-mail address removed), and your private mail is
(e-mail address removed); if you send email through your office mail server
with the envelope "MAIL FROM: (e-mail address removed)\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.
 
C

Christos Georgiou

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top