Request: Lib to create HTML E-mail?

J

James Britt

I'm looking for code to create HTML E-mail. I'd rather not re-invent
anything if possible, though my search for such a beast has turned up
nothing that does quite what I want. About the closest is SimpleMail,
but it does not handle inline images, which is critical.

(I've also started looking at RubyMail, though I haven't seen any
indication that it supports inline image references.)

What I would *really* like is something that takes as input an HTML
string and a hash of header values (to, from, subject, etc.), and
creates the multipart/alternative E-mail by magic.

Ideally, it would create a plain text version, followed by the HTML
version. If the HTML contains any relative URLs, they would be
interpreted as local file paths; the file would be slurped in,
uuencoded, and added to the E-mail as a multipart/related segment, and
the img href value then converted to a cid: reference.

I've done some hacking about on my own, munging up a copy of SimpleMail,
but before I go too far I thought I'd just check to see if someone beat
me to it.

Any tips or pointers appreciated; please, no lectures on the evils of
HTML E-mail; this is for a specific project for people who actually
*request* such E-mail.

Thanks!


James
 
K

Kirk Haines

I'm looking for code to create HTML E-mail. I'd rather not re-
invent anything if possible, though my search for such a beast has
turned up nothing that does quite what I want. About the closest is
SimpleMail, but it does not handle inline images, which is critical.

I do HTML emails regularly, using tmail. They, however, are simple straight
HTML mails and not multipart/MIME.
What I would *really* like is something that takes as input an HTML
string and a hash of header values (to, from, subject, etc.), and
creates the multipart/alternative E-mail by magic.

That would be _fantastic_. I would use such a thing quite often. I never
did find anything like that, however, when I was doing my checking. I
strongly encourage you to continue on your hacking down this path, as you
have one eager user awaiting your results already!


Kirk Haines
 
W

William Park

James Britt said:
I'm looking for code to create HTML E-mail. I'd rather not re-invent
anything if possible, though my search for such a beast has turned up
nothing that does quite what I want. About the closest is SimpleMail,
but it does not handle inline images, which is critical.

(I've also started looking at RubyMail, though I haven't seen any
indication that it supports inline image references.)

What I would *really* like is something that takes as input an HTML
string and a hash of header values (to, from, subject, etc.), and
creates the multipart/alternative E-mail by magic.

Ideally, it would create a plain text version, followed by the HTML
version. If the HTML contains any relative URLs, they would be
interpreted as local file paths; the file would be slurped in,
uuencoded, and added to the E-mail as a multipart/related segment, and
the img href value then converted to a cid: reference.

I've done some hacking about on my own, munging up a copy of SimpleMail,
but before I go too far I thought I'd just check to see if someone beat
me to it.

Any tips or pointers appreciated; please, no lectures on the evils of
HTML E-mail; this is for a specific project for people who actually
*request* such E-mail.

For dis/assembling MIME email, look over
http://freshmeat.net/projects/mboxsh/
by yours truly.

You can create text version using Lynx. But, if you only have HTML
file, then including local file and images are messy to do, because you
have to parse HTML to figure out what path to include. It would be a
bit easier if you already know what file or image to include in MIME
email.
 
J

James Britt

William said:
For dis/assembling MIME email, look over
http://freshmeat.net/projects/mboxsh/
by yours truly.

I shall do that now!
You can create text version using Lynx. But, if you only have HTML
file, then including local file and images are messy to do, because you
have to parse HTML to figure out what path to include. It would be a
bit easier if you already know what file or image to include in MIME
email.

Actually, I think that part would be fairly easy. My plan was to pass
the source HTML through the REXML stream or pull parser and emit a
plain-text version (possibly wrapping pseudo-markup, such as *bold* or
/italics/, when encountering specific tags.) At that time, any img
element can be parsed for the src attribute. If the URL doesn't start
with http then the code assumes a local relative file. The file is
grabbed, uuencoded, a CID ref generated for it, and the CID put in place
of the original src value.

Or something along those lines.

(Actually, this presumes the source markup is XHTML, not HTML. An
alternative my be to use the htmlparser lib, but then the code starts
acquire 3rd-party dependencies. )


James
 

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,804
Messages
2,569,665
Members
45,434
Latest member
Pinuz117Sapuz

Latest Threads

Top