So I'm nearly complete with setting up a mailer in my Rails app, but I cannot seem to understand one of the pieces of information on https://guides.rubyonrails.org/action_mailer_basics.html.
According to this tutorial, you can specify your own smtp_settings
option, so that you can send mail like:
def welcome_email
smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.com',
user_name: 'myfromemail@example.com',
password: "myPassword",
authentication: :plain,
enable_starttls_auto: true
}
mail(to: "destination@example.com",
subject: "Test Notification",
smtp_settings: smtp_settings
)
end
but this doesn't actually work. The same example at the bottom uses delivery_method
and passes over a hash just like I used in this example.
If I try to use the .deliver
method on the mailer, this is the error I get:
Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25)
It's almost like it's completely ignoring the smtp settings that I passed to the mail
function. What am I doing wrong here?
I've looked at examples from How to send emails with multiple, dynamic smtp using Actionmailer/Ruby on Rails, but this method does not work:
delivery_method.settings.merge!(smtp_settings)
because the delivery_method
is actually :smtp
and it's not possible.
The delivery_method
option seems to work, but I need to pass additional stuff over like authentication, SSL/TLS, and even the port. Those don't seem to be offered by the delivery_method
option.
Trying to implement one of the solutions on that post gives me this error:
MyMailer.delivery_method.settings.merge!(smtp_settings)
Traceback (most recent call last):
1: from (irb):3
NoMethodError (undefined method `settings' for :smtp:Symbol)