Hi,

I want to make a mail message with attachments and send it.  However, 
its the making attachments bit that is causing me difficulty.

The Net::SMTP docs say I should use RubyMail or TMail to compose messages

RubyMail looked very good.  It was Ruby only, so you could include the 
code in a directory with yours, and the user would not have to install 
anything (apart from Ruby, of course.)  But it doesn't support adding 
of attachments very well!

RubyMail is available here: http://www.lickey.com/rubymail/

However, I found a small snippet of code on the net, which I thought 
would work.  It didn't  (its the 'add_attachment' method in the code 
below.)  Anyway, I'm stumped: why isn't this code working?

#!/usr/bin/env ruby

require 'rmail'

module RMail

     class Message
	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')
	    File::open(path) do |fh|
		part.body = fh.sysread(8192).unpack('a*').pack('m')
	    end
	    self.add_part(part)
	end
     end
end

msg = RMail::Message.new
msg.body = "Hello"
msg.header.subject = "A Subject"
msg.header.from = "a / b.com"
msg.header.to = "c / d.com"
msg.add_file("jmparse.rb")
msg.to_s


Could someone please tell me a way of attaching a file to a mail 
message?!  I need a portable solution that works possibly without 
custom C code (unlike TMail, which uses a C library.)

Thanks