Sinatra, Pony gem: NoMethodError

491 Views Asked by At

I am trying to send an e-mail using Pony and get the
NoMethodError at /
undefined method `address' for #Mail::Message:.
error. This is my code so far:

post '/' do
Pony.options = { :from           => '[email protected]',
                 :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: "[email protected]", body: 'hi')
redirect '/'
end

when running bundle list it does show pony (1.10). What could go wrong?

1

There are 1 best solutions below

3
On BEST ANSWER

:address, :port, etc. go inside a :via_options hash.

Per 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
  }

Therefore, you'll want:

post '/' do

  Pony.options = {   
                   :from           => '[email protected]',
                   :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: "[email protected]", body: 'hi')

  redirect '/'

end