我正在Sinatra中创建一个表单,该表单将使用Pony gem将数据发送到提交的电子邮件中。到目前为止,这是我的代码:
post '/pemco' do
Pony.mail(
:from => params[:name] + "<" + params[:email] + ">",
:to => '___@yandex.ru',
:subject => params[:name] + " has contacted you",
:body => params[:message],
:via => :smtp,
:via_options => {
:address => 'smtp.yandex.ru',
:port => '465',
:enable_starttls_auto => true,
:user_name => '___',
:password => '___',
:authentication => :plain
})
redirect '/'
end
我按提交,响应暂停了一段时间然后我得到 Net :: ReadTimeout file:protocol.rb location:rescue in rbuf_fill line:158 错误。我做错了什么?
答案 0 :(得分:3)
此代码适用于 yandex.ru (您需要到此处https://mail.yandex.ru/neo2/#setup/client并允许所有内容):
post '/sent' do
Pony.mail(
:to => "_yourEmail_@yandex.ru",
:from => "_sameYourEmail_@yandex.ru",
:via => :smtp,
:via_options => {
:address => 'smtp.yandex.ru',
:port => '25',
:enable_starttls_auto => true,
:user_name => '_yourUsername_',
:password => '_yourPassword_',
:authentication => :plain
})
end
相同的代码适用于 mail.ru (通常您不需要做任何其他事情)。