简体   繁体   中英

A ruby mail object turns itself into a String before being sent to exim

Running ubuntu 14.04 ruby 2.0 Rails 4 Mail gem 2.5.4

In the rails console

mail = Mail.new do
*>  from     'me@test.com'
*>  to       'mbennon@gmail.com'
*>  subject  'Here is the image you wanted'
*>  body     'this is a test'  
*>end

> mail.delivery_method :exim, :location => "/usr/sbin/exim"
> mail deliver

I receive the following error (before it gets to exim)

NoMethodError: undefined method encoded' for #<String:0x0000000947f9d8> from /home/mark/.rvm/gems/ruby-2.0.0-p247/gems/mail 2.5.4/lib/mail/network/delivery_methods/exim.rb:46:in block in call'

There is a method encoded in mail. It seems that it is just string at the time of the call...

There seems to be a problem with delivery_method. Is the encoded called inside delivery_method function?

It is a bug in Mail::Exim . the bug comes up on the deliver call. It tries to decode the mail message twice, once when checking the params and another time just before it goes to IO.

My fix for the version I have currently in exim.rb

def self.call(path, arguments, destinations, mail)
        popen "#{path} #{arguments}" do |io|
    io.puts mail.encoded.to_lf
    io.flush
  end
end

change

io.puts mail.encoded.to_lf

to

io.puts mail.to_lf

I renamed the mail param as well but the above should be clear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM