generate and send mail with python: tutorial
aspineux at gmail.com
Fri Aug 12 14:59:40 CEST 2011
On Aug 12, 8:51 am, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Thu, 11 Aug 2011 08:07:09 -0700 (PDT), aspineux <aspin... at gmail.com>
> declaimed the following in gmane.comp.python.general:
> > Hi I have written a tutorial about how to generate and send emails
> > with python.
> Is that really such a difficult task?
Yes it's difficult to make an _universal_ mail parser, able to handle
mails from different MUA, using different charsets.
Some emails that break RFC's requires at least some background
to know which rules can be missed by some MUA !
Handle mail from a unique source or similar sources is easy.
Using try and error method is fine for this kind of job, you don't
even need to care if the email you're parsing match the RFC's or not.
My "parser" functions have been tested over 20.000 mails from all
around the world using some human and automated verifications !
Generating emails is not easy, when mixing internationalized
subject and content. Integrating text, html, attachment and embedded
images in one single email looks to me difficult enough to require
At least read carefully all my articles to get an idea about the
this is what I try to explain.
> Okay, I didn't really use Python for the entire creation of the
> message... But my first real Python program (using 1.4 or 1.5, whatever
> was included in the first "Programming Python" disk, for AmigaOS) was a
> rudimentary outgoing SMTPd which had to parse headers from message
> files "queued" by an ARexx script from an Amiga version of ELM, then
> handshake with the ISP SMTPd to relay the message onward. It took less
> than a week after buying the book that I had this ARexx/Python hybrid
> working -- and it worked better than either C-language programs I'd
> downloaded (at that period of time, Amiga email programs ONLY read from
> local spool and queued to local spool; separate programs had to be used
> to read POP3 and send SMTP... My first SMTP utility presumed 1) direct
> connection to destination address, 2) created an email file for each
> address -- problem: if a destination did not have a receiving SMTPd [ie,
> one needed to do an MX lookup instead] it would hang trying to send that
> message, and never process others... The second program used ISP relay
> -- but it only parsed the "TO:" header, and thereby failed to handshake
> CC and BCC destinations)
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr... at ix.netcom.com HTTP://wlfraed.home.netcom.com/
More information about the Python-list