Sending Email using Ruby
I am getting the following error while trying to send an email.
Errno::ECONNREFUSE开发者_高级运维D: Connection refused - connect(2)
Code that sends the email
Reminder.new_event(event_owner.email).deliver!
My Email settings are
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "google.com",
:authentication =>"login",
:user_name => "email address",
:password => "password",
:enable_starttls_auto => true
}
Could you please help me. Thanks
Try with
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "google.com",
:authentication =>"plain",
:user_name => "email address",
:password => "password",
}
Note the:
:authentication =>"plain",
and
:enable_starttls_auto => true
is the default value, no need to specify it.
Try the following in your config/application.rb file :
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "google.com",
:authentication =>"plain",
:user_name => "email address",
:password => "password",
:enable_starttls_auto => true
}
To send the email, try (note, without ! at the end)
Reminder.new_event(event_owner.email).deliver
And try sending a test email to an email address that is not the same as the sending gmail account (as gmail won't allow that through).
I did only have success when omitting both :port and :domain, but had to set :tls to true.
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:tls => true,
:address => "smtp.gmail.com",
:authentication => :plain,
:user_name => "full-email-address",
:password => "password"
}
精彩评论