Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems trying to Parse -> Deliver an existing mail #79

Closed
weppos opened this issue Jul 2, 2010 · 6 comments
Closed

Problems trying to Parse -> Deliver an existing mail #79

weppos opened this issue Jul 2, 2010 · 6 comments

Comments

@weppos
Copy link
Contributor

weppos commented Jul 2, 2010

Here's the scenario. I have a .eml file containing a received email. I'd like to be able to parse the email and re-deliver it to an arbitrary email address.

The following code doesn't work

Mail.read("/path/to/file") do
  to "[email protected]"
  deliver
end

No errors, it simply doesn't deliver the email. I guess the existing headers cause some kind of conflict because the following workaround seems to work

# I must use #tap to workaroung bug #59
original = Mail.read("/path/to/file")
Mail.read("/path/to/file").tap do |mail|
  mail.header   = ""
  mail.to       = "[email protected]"
  mail.from     = original.from
  mail.subject  = original.subject
  # ...
end

However, with the following code (and a few other variants) I'm experiencing a really weird behavior. When the email is received, it looks like different compared to the original one. It seems that Mail adds some extra-stuff to the body parts causing mail clients (such as Gmail) to render the content in a different way.

For instance, if the email contains two parts (a text part and an attachment), the final email is rendered as the text part would be a second attachment.

See http://twitpic.com/21sqgs vs http://twitpic.com/21sqh8

Any idea?

I can also send you via email the two email sources (the original one and the clone), if you need them.

@mikel
Copy link
Owner

mikel commented Sep 11, 2010

I would say your method of doing it above is probably not the best way.

Better instead fo read in the mail message, then perform actions on it:

mail = Mail.read('path/to/file')
mail.to = "my address"
mail.deliver

Please let me know if this fixes it.

@weppos
Copy link
Contributor Author

weppos commented Sep 12, 2010

Hi Mikel, unfortunately the script you posted didn't worked.
No error messages, no warning. The email was simply not delivered.

I tried it even before opening the issue (see the beginning of the issue body),
but the problem seems to be represented by the "Received:" header
which prevent the email to be delivered again.

@mikel
Copy link
Owner

mikel commented Sep 13, 2010

Can you send me the original emails?

Send to my Gmail account: raasdnil.

Mikel

@weppos
Copy link
Contributor Author

weppos commented Sep 15, 2010

I tried again the suggested script with the latest Mail version

Mail.defaults do
  delivery_method :smtp, { :address              => "smtp.gmail.com",
                           :port                 => 587,
                           :domain               => '...',
                           :user_name            => '...',
                           :password             => '...',
                           :authentication       => 'plain',
                           :enable_starttls_auto => true  }
end

mail = Mail.read('/Users/weppos/Desktop/email.eml')
mail.to = "..."
mail.deliver

and I'm not receiving this error.

ruby-1.8.7-p249 > mail.deliver
Net::SMTPFatalError: 555 5.5.2 Syntax error. i14sm1266001wbe.6

    from /Users/weppos/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/smtp.rb:930:in `check_response'
    from /Users/weppos/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/smtp.rb:899:in `getok'
    from /Users/weppos/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/smtp.rb:828:in `mailfrom'
    from /Users/weppos/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/smtp.rb:653:in `sendmail'
    from /Users/weppos/.rvm/gems/ruby-1.8.7-p249/gems/mail-2.2.6.1/lib/mail/network/delivery_methods/smtp.rb:102:in `deliver!'
    from /Users/weppos/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/smtp.rb:526:in `start'
    from /Users/weppos/.rvm/gems/ruby-1.8.7-p249/gems/mail-2.2.6.1/lib/mail/network/delivery_methods/smtp.rb:101:in `deliver!'
    from /Users/weppos/.rvm/gems/ruby-1.8.7-p249/gems/mail-2.2.6.1/lib/mail/message.rb:1892:in `do_delivery'
    from /Users/weppos/.rvm/gems/ruby-1.8.7-p249/gems/mail-2.2.6.1/lib/mail/message.rb:228:in `deliver'
    from (irb):13

I'm sending you the email.

@kewinwang
Copy link

hi I get the same problem as wepps , but I use deplayed_job to send the email .the error ouput is :
502 5.5.1 Error: command not implemented /usr/local/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:787:in check_response' /usr/local/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:760:ingetok'
/usr/local/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:747:in starttls' /usr/local/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:478:indo_start'
/usr/local/lib/ruby/gems/1.8/gems/tlsmail-0.0.1/lib/net/smtp.rb:440:in start' /usr/local/lib/ruby/gems/1.8/gems/mail-1.3.2/lib/mail/network/delivery_methods/smtp.rb:78:indeliver!'
/usr/local/lib/ruby/gems/1.8/gems/mail-1.3.2/lib/mail/network/deliverable.rb:11:in perform_delivery!' /usr/local/lib/ruby/gems/1.8/gems/mail-1.3.2/lib/mail/message.rb:68:indeliver!'
/usr/local/lib/ruby/gems/1.8/gems/delayed_job-2.0.5/lib/delayed/performable_method.rb:35:in send' /usr/local/lib/ruby/gems/1.8/gems/delayed_job-2.0.5/lib/delayed/performable_method.rb:35:inperform'
/usr/local/lib/ruby/gems/1.8/gems/delayed_job-2.0.5/lib/delayed/backend/base.rb:74:in invoke_job' /usr/local/lib/ruby/gems/1.8/gems/delayed_job-2.0.5/lib/delayed/worker.rb:122:inrun'
/usr/local/lib/ruby/1.8/timeout.rb:62:in `timeout'

I don't know why? maybe timeout or others?

@jeremy
Copy link
Collaborator

jeremy commented Jan 26, 2013

It's possible to redeliver emails, but it takes some finesse. Changing the To: header on the message itself is insufficient since the message still has the original delivery headers, SPF verification, DKIM signature, etc.

Your best bet is to leave the message entirely as-is, but send it out in a different SMTP envelope. That means changing the envelope's To: address (corresponding to SMTP RCPT TO) to the new recipient address. Check out #477 for support.

@jeremy jeremy closed this as completed Jan 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants