The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Fwding with RubyMail

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Fwding with RubyMail Posted: Jan 20, 2005 2:10 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Fwding with RubyMail
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

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.

Read: Fwding with RubyMail

Topic: An unusual high presence of Macs Previous Topic   Next Topic Topic: Showin Up On Technorati

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use