Joshua Baer
2007-Jul-29 14:24 UTC
Reading an email from an mbox file and resending to a different address without modification
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-q89RzV0OsXQ@public.gmane.org", "josh-q89RzV0OsXQ@public.gmane.org" 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-q89RzV0OsXQ@public.gmane.org>\nX-Original-To: xxx-2ignx7OV+QJWk0Htik3J/w@public.gmane.org \nDelivered-To: xxx-2ignx7OV+QJWk0Htik3J/w@public.gmane.org\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-2ignx7OV+QJWk0Htik3J/w@public.gmane.org>; 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-2ignx7OV+QJWk0Htik3J/w@public.gmane.org>; Sat, 14 Jul 2007 12:37:13 -0500 (CDT)\nResent- Message-Id: <17203735.46831184153713889.JavaMail.root-07OsOYd0Zv4@public.gmane.org>\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-07OsOYd0Zv4@public.gmane.org>\nResent-To: xxx-2ignx7OV+QJWk0Htik3J/w@public.gmane.org\nFrom: Stanford Technology Ventures Program <support-VCqTbks9JBdegcJQxxnBRDe48wsgrGvP@public.gmane.org>\nSubject: Educators Corner highlights - July edition\nResent-From: Joshua Baer <josh-q89RzV0OsXQ@public.gmane.org>\nDate: Wed, 11 Jul 2007 04:35:13 -0700 (PDT)\nTo: Joshua Baer <xxxx-q89RzV0OsXQ@public.gmane.org>\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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---