Sinatra,Pony gem:NoMethodError

时间:2014-08-07 15:15:53

标签: ruby sinatra pony

我正在尝试使用Pony发送电子邮件并获取 / strong处的 NoMethodError #Mail :: Message:。错误的未定义方法`address'。到目前为止,这是我的代码:

post '/' do
Pony.options = { :from           => '___@yandex.ru',
                 :via            => :smtp,
                 :address        => 'smtp.yandex.ru',
                 :port           => '465',
                 :user_name      => '___',
                 :password       => '___',
                 :authentication => :plain, 
                 :domain         => "http://127.0.0.1:9393/"
                }
Pony.mail(subject: 'Hello', to: "___@yandex.ru", body: 'hi')
redirect '/'
end

运行捆绑列表时,会显示 pony(1.10)。可能出现什么问题?

1 个答案:

答案 0 :(得分:2)

:address:port等进入:via_options哈希。

the documentation

  :via_options => {
    :address        => 'smtp.yourserver.com',
    :port           => '25',
    :user_name      => 'user',
    :password       => 'password',
    :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
    :domain         => "localhost.localdomain" # the HELO domain provided by the client to the server
  }

因此,您需要:

post '/' do

  Pony.options = {   
                   :from           => '___@yandex.ru',
                   :via            => :smtp,
                   :via_options    => {
                     :address        => 'smtp.yandex.ru',
                     :port           => '465',
                     :user_name      => '___',
                     :password       => '___',
                     :authentication => :plain, 
                     :domain         => "http://127.0.0.1:9393/"
                    }
                 } 

  Pony.mail(subject: 'Hello', to: "___@yandex.ru", body: 'hi')

  redirect '/'

end