very small python smtpish send

B

Brad Tilley

Anyone know of a small Python script that acts as a slimmed down smtp
server (just sends from the local machine)? I currently use a smtp
server for sending email reports from machines, but as machines travel
outside of our lan, the smtp server refuses to relay their messages. So,
I thought it would be better if each machine had its own little mail
sender this way, it could continue reporting no matter where it was located.

These are all Windows machines... is there a Windows equivalent to
'stdin | mail -s "Subject" (e-mail address removed)' that comes on most Unix
machines?
 
R

Roman Suzi

Anyone know of a small Python script that acts as a slimmed down smtp
server (just sends from the local machine)? I currently use a smtp
server for sending email reports from machines, but as machines travel
outside of our lan, the smtp server refuses to relay their messages. So,
I thought it would be better if each machine had its own little mail
sender this way, it could continue reporting no matter where it was located.

It is not good to send mail from anywhere because direct smtp from
arbitrary IPs are often considered spamish. Consider setting up
secure smtp server which will receive authenticated mail from any
corporate client on special port.
These are all Windows machines... is there a Windows equivalent to
'stdin | mail -s "Subject" (e-mail address removed)' that comes on most Unix
machines?



Sincerely yours, Roman Suzi
 
T

Tim Williams

On Fri, 8 Oct 2004, Brad Tilley wrote:

Anyone know of a small Python script that acts as a slimmed down smtp
server (just sends from the local machine)? I currently use a smtp
server for sending email reports from machines, but as machines travel
outside of our lan, the smtp server refuses to relay their messages.

OK, so the clients are sending email to addresses that are not local to
your lan's server (otherwise there would be no relaying attempt)

Have you considered turning on authentication on the lan server, you can
then allow relaying only from an authenticated "client".
I thought it would be better if each machine had its own little mail
sender this way, it could continue reporting no matter where it was
located.

Sending directly from the client to the recipient address's server is
valid, doesn't need authentication, and relatively simple to do using
smtplib.py . However, nowadays this may be problematic because of
increasing anti-spam measures that *might* cause the email to be refused on
a variety of criteria (IP address (RBL) , IP address reverse lookup,
possibly SPF, etc etc ).

import smtplib
try:
s = smtplib.SMTP(outgoing-server)
failed = s.sendmail(out_from, to_list , msg)
except smtplib.SMTPRecipientsRefused, x :
do something # for recip in x.recipients: info = x.recipients[recip]
except smtplib.SMTPDataError, x:
do something # x[0], x[1]
except smtplib.SMTPSenderRefused, x :
do something # x.sender, x.smtp_code, x.smtp_error
except:
do something

(failed contains a list of failed recipients if *some* but not all failed,
if all failed then use
except smtplib.SMTPRecipientsRefused, x :)

Alternatively there are some free mail SPs out there that provide
authenticated outgoing servers that you could use if you can't turn on
authentication on your lan server.
 

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

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,684
Latest member
sparada

Latest Threads

Top