hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

So, Mail Attachments #

by why in inspect

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.)

said on 23 Jan 2005 at 23:17

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)
end
said on 24 Jan 2005 at 00:12

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.