Michael
Michael

Reputation: 219

Rails Action Mailer async ECONNREFUSED localhost:25

I am testing out Action Mailer for the first time, attempting to configure a User Welcome email upon signup. I understand that an email will not actually be send in development mode, but the logs seem to be showing an error.

Upon creating a user, my logs look like this. It appears that my email is created properly in both plain text and html, but after I see the error: Errno::ECONNREFUSED (Connection refused - connect(2) for 127.0.0.1:25)

My User.create action:

    def create
    user = User.create(user_params)
    if user.valid?
        WelcomeMailer.welcome.deliver_later
        session[:current_user] = user.id
        return render json: user, status: 201
    else
        return render json: { error: user.errors.full_messages }, status: 404
    end
end

I have tried both WelcomeMailer.welcome.deliver and WelcomeMailer.welcome.deliver_now but they don't work either (although the errors are not related to async).

Upvotes: 0

Views: 174

Answers (1)

Vi.
Vi.

Reputation: 1022

Did you set action_mailer configuration for Gmail in your environment?

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address:              'smtp.gmail.com',
  port:                 587,
  domain:               'example.com',
  user_name:            '<username>',
  password:             '<password>',
  authentication:       'plain',
  enable_starttls_auto: true}

Take a look at the guide to have a better understanding of ActionMailer

Upvotes: 1

Related Questions