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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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)
Greetings,

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

I am reading messages out of an mbox file and parsing them into RMail
objects with RMail::Parser.read(). 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
Date.

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, "josh@xxx.com", "josh@xxx.com"

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
formatting?

Thanks!

~Josh

---

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

Return-Path: <josh@xxx.com>\nX-Original-To: xxx@mail.xxx.com
\nDelivered-To: xxx@mail.xxx.com\nReceived: from ms-smtp-04.xxx.rr.com
(ms-smtp-04.xxx.rr.com [xx.xx.47.43])\n\tby mail.xxx.com (Postfix)
with ESMTP id 15CE495A92\n\tfor <xxx@mail.xxx.com>; Sat, 14 Jul 2007
12:37:18 -0500 (CDT)\nReceived: from [10.0.1.5] (cpe-
xxx-157-199.xxx.xxx.rr.com [xx.xx.157.199])\n\tby ms-
smtp-04.xxx.rr.com (8.13.6/8.13.6) with ESMTP id l6EHbCjV027495\n\tfor
<xxx@mail.xxx.com>; Sat, 14 Jul 2007 12:37:13 -0500 (CDT)\nResent-
Message-Id: <17203735.46831184153713889.JavaMail.root@xxx.edu>\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:
<26386B1F-3612-4CDB-8535-01FE7AADCE67@xxx.edu>\nResent-To:
xxx@mail.xxx.com\nFrom: Stanford Technology Ventures Program
<support@stvp1.stanford.edu>\nSubject: Educators Corner highlights -
July edition\nResent-From: Joshua Baer <josh@xxx.com>\nDate: Wed, 11
Jul 2007 04:35:13 -0700 (PDT)\nTo: Joshua Baer <xxxx@xxx.com>\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.