0

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

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

运行bundle list时,它确实显示pony (1.10)。会出什么问题?

4

1 回答 1

2

:address, :port, 等进入:via_options散列。

根据文档

  :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
于 2014-08-07T15:22:45.593 回答