So, Mail Attachments #
A couple days ago, the topic was RubyMail. Dan Berger’s question was: how to do attachments. I didn’t look deep enough to figure out what the answer was.
But here’s a script called samail from Japan. The script is halfway down the page and is designed to be used like so:
$ samail -v --to "redhanded@infoseek.jp example@example.com" \
--from redhanded@infoseek.jp --smtp smtp.example.com \
--attachment "logo.png /tmp/backup.tar.bz2"
Bit more complicated version 0.4 here. Bunch of GMail scripts to go with it. (seen on del.icio.us/eban.)


Matt Armstrong
Here is a method sent to me by John Labovitz since he found RubyMail’s lack of an #attach_file method, well, lacking. It will likely show up in RubyMail as an #attach_file method instead of #add_file.
def add_file(path, content_type='application/octet-stream') part = RMail::Message.new part.header.set('Content-Type', content_type) part.header.set('Content-Disposition', 'attachment', 'filename' => File.basename(path)) part.header.set('Content-Transfer-Encoding', 'base64') part.body = '' File.open(path) do |fh| part.body << fh.sysread(8192).unpack('a*').pack('m') end self.add_part(part) endwhy
Ah, great, good, and very concise. I love RubyMail’s handling of multipart messages. Very slick. But, yes, some time-saving methods would do a world.
Comments are closed for this entry.