[perl-python] sending email

Xah Lee xah at xahlee.org
Sat Jan 29 18:36:05 EST 2005

# -*- coding: utf-8 -*-
# Python

# Suppose you want to spam your friend, and you have lots of
# friends. The solution is to write a program to do it. After a gander
# at python docs, one easily found the module for the job.
# see http://python.org/doc/2.3.4/lib/SMTP-example.html

# the code is a bit long with the command line, but the key lies at
# the bottom four lines. The gist is this:

import smtplib

fromAddr='xah at xahlee.org';
toAddr='xah at xahlee.org';
text='''Subject: newfound love

Hi friend,

long time no write, i have a new manifesto i
think it would be of interest for you to peruse.

server = smtplib.SMTP(smtpServer)
server.sendmail(fromAddr, toAddr, text)

# save this file as x.py and run it.
# it should send out the mail.

# the set_debuglevel() is nice because you see all the interactions
# with the smtp server. Useful when you want to see what's going on
# with a smtp server.
in Perl, there are not just one, two, or 3 modules that does the job,
each with slight problems. Here's how the situation stands as of 2001

For Perl libraries that deals with RFC 821, I personally know of

* Mail::Mailer. Mentioned in most Perl books.
Written or maintained by Graham Barr.

* Mail::Send, maintained by Graham Barr , originally
written by Tim Bunce.

* Mail::Sendmail by Milivoj Ivkovic.

The first two has glaring problems. I'm sorry i forgot what they
are. I think Mail::Mailer has a bug on the from field. i.e. it ignores
what you gave. I'm currently using Mail::Sendmail, and according to a
ex-colleague, it has problems with some DNS mail exchange entries.

for some discussion of the plethora of Perl mail modules and their
short-cummings, see http://alma.ch/perl/mail.htm
 xah at xahlee.org

More information about the Python-list mailing list