[ale] HTML mail generation

Brian Pitts brian at polibyte.com
Thu Mar 6 16:16:46 EST 2008


Randy Ramsdell wrote:
> Anyone have a suggestion as to what is the best reference about how to 
> type the actual html mail and pipe that to a text based mailer such as 
> nail. I simply do not know the format that a mail server needs to see in 
> a piece of mail. Maybe some sort of a template.

I have a small ruby script that emails me the results of craigslist 
searches. Generating the html message wasn't hard; I just looked at the 
source of an html email I'd received. The email generation and sending 
looks like

msg = <<END
From: CraigScrape <donotreply at polibyte.com>
To: Brian Pitts <brian at polibyte.com>
Subject: New Craigslist Ads
Date: #{Time.now.to_s}
Content-Type: text/html; charset=ISO-8859-1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<h2>Results</h2>
#{new_results * "<br>"}
</body>
</html>
END

Net::SMTP.start("localhost", 25) do |smtp|
   smtp.send_message msg,
   "donotreply at polibyte.com",
   "brian at polibyte.com"
end

I stopped using this once I realized I could get an rss feed of search 
results.

-Brian


More information about the Ale mailing list