Forum: Ruby on Rails Reading an email from an mbox file and resending to a differ

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
362c6f34f91739ed7b863ede1410f82f?d=identicon&s=25 Joshua Baer (Guest)
on 2007-07-29 16:25
(Received via mailing list)

I'm trying to emulate the "Redirect" function of some email clients
but am not having much success. I am sending messages with
ActionMailer templates just fine so I'm pretty sure my environment is
set up correctly and that my mail server is accepting the messages to

I am reading messages out of an mbox file and parsing them into RMail
objects with Then I'm storing some info about
the message as well as storing the a text version of the RMail object
in a field as the "raw" message (I get the text version of RMail using
to_s() )

At a different point in the program, I want to "resend" or "redirect"
the message to an external email address - but I want it to appear in
their mailbox unmodified from the original.

I thought the easiest way to do this would be to use Net::SMTP.start()
and pass it the "raw" message as well the from/to address for the SMTP
transaction (which shouldn't affect the RFC822 headers in the original
message being delivered). I realized along the way that I need to
delete the first line from the mbox file that contains the From and

When I try this with simple text emails it seems to work. But when I
try to attach MIME emails it seems to get confused and creates a new
set of RFC822 headers and puts the entire MIME message (including its
RFC822 headers) into the body of the new message that is sent.

      smtp.send_message raw_mail, "", ""

Any pointers? Is there an easier way to resend a raw RFC822 message
than Net::SMTP.start() ? Any idea what could be wrong with my message




Here is a sample of the "raw" output of a message (truncated)

Return-Path: <>\nX-Original-To:
\nDelivered-To:\nReceived: from
( [xx.xx.47.43])\n\tby (Postfix)
with ESMTP id 15CE495A92\n\tfor <>; Sat, 14 Jul 2007
12:37:18 -0500 (CDT)\nReceived: from [] (cpe- [xx.xx.157.199])\n\tby ms- (8.13.6/8.13.6) with ESMTP id l6EHbCjV027495\n\tfor
<>; Sat, 14 Jul 2007 12:37:13 -0500 (CDT)\nResent-
Message-Id: <>\nMime-
Version: 1.0 (Apple Message framework v752.2)\nContent-Type: multipart/
alternative; boundary=Apple-Mail-17--30998656\nResent-Date: Sat, 14
Jul 2007 12:37:11 -0500\nMessage-Id:
<>\nResent-To:\nFrom: Stanford Technology Ventures Program
<>\nSubject: Educators Corner highlights -
July edition\nResent-From: Joshua Baer <>\nDate: Wed, 11
Jul 2007 04:35:13 -0700 (PDT)\nTo: Joshua Baer <>\nX-
Mailer: Apple Mail (2.752.2)\nX-Virus-Scanned: Symantec AntiVirus Scan
Engine\n\n\n--Apple-Mail-17--30998656\nContent-Transfer-Encoding: 7bit
\nContent-Type: text/plain;\n\tcharset=US-ASCII;\n\tdelsp=yes;\n
\tformat=flowed\n\nTrouble viewing this email? View it online\n
\nRecently Added Videos\n\nListed below are a few video clips of
recent speakers from the  \nEntrepreneurial Thought Leaders Seminar.\n
\nIncentives for People in a Community-Based Organization\n\nMitchell
Baker, Mozilla Corporation - 2 min. 10 sec.\nMitchell Baker, CEO of
Mozilla, describes the richness in decision- \nmaking authority that
one is endowed with while working in a  \ncommunity-based organization
like Mozilla. She talks about the
This topic is locked and can not be replied to.