rubysinatrapony

Sinatra, Pony gem: NoMethodError


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           => '___@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

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


Solution

  • :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           => '___@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