Fwding with RubyMail #
When it comes to e-mail manipulation, RubyMail has always been my answer. The fortunate thing about RubyMail is that it parses each message into RMail::Message objects, which can also be converted back into e-mail with to_s
.
This makes for simple modification of messages. The issue is slightly complicated by stuff like multiple From:
fields. So, if you’re forwarding a message and simply want to modify header fields, be sure to delete the fields from the message first.
Here’s an excerpt from a simple mailing list script:
msg.header.delete('From') msg.header.subject = "[#{ list_title }] #{ msg.header.subject }" msg.header['From'] = "#{ from_recip } <#{ reply_to }>" Net::SMTP.start( 'localhost' ) do |smtp| list['recipients'].each do |recip| to_email = "#{ recip['name'] } <#{ recip['email'] }>" msg.header.delete('To') msg.header['To'] = to_email smtp.send_message( msg.to_s, msg.header['Reply-To'], to_email ) end end
Note: This code won’t run from Irb unless you setup some variables and arrays. The point is to simply illustrate deletion of the header fields.
Daniel Berger
I’m still looking for an email package that will let me do “smtp.attach_file(‘somefile.xls’)”. Perl’s Mail::Sender can do this. Time to swipe some code? Or can RubyMail already do this?
that guy
the new comment boxes are sexual.
another guy
They make comments look as if etched eternally into stone. Which is nice, come to think of it.
one lady
You guys have your whole lives ahead of you to talk about boxes.
that guy
unless we all die of rubella
Jim Beam
Gikt Agur!
Comments are closed for this entry.