我正在尝试使用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)。可能出现什么问题?
答案 0 :(得分: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