ActionMailer: end of file reached (EOFError)

I am studying Peter Cooper’s book Beginning Ruby. According to the author ActionMailer can be used independently of Rails. So I installed the ActionMailer gem in a dedicated gemset and wrote the code below which is an extract from the book:


require 'action_mailer'
ActionMailer::Base.smtp_settings = {
:address => "smtp.mail.yahoo.com",
:port => 465,
:authentication => :login,
:user_name => "username@yahoo.com",
:password => "password",
:openssl_verify_mode => :ssl
}
class Emailer < ActionMailer::Base
def test_email(email_address, email_body)
mail(to: email_address, from: 'username@yahoo.com', subject: 'action mailer test', body: email_body)
end
end
Emailer.test_email('username@gmail.com', 'This is a test e-mail!').deliver_now

When I run the rb file containing the above code I receive a long traceback (21 lines) with the following error message:

/home/krfg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/protocol.rb:189:in `rbuf_fill': end of file reached (EOFError)

Why do I receive this error?
Also I tried run test_email on an instance of the class Emailer but I receive undefined method `deliver_now' for #<Mail::Message:0x0000000002256b68>
 

EOF usually mean you reached the end of the file or are to read past it.

So why my code produces this error message? I checked all the required ends: there are two, one for class Emailer and one for method test_email

Solved at Stackoverflow