smtp-authlearn-ruby-on-rails

SMTP-AUTH requested but missing user name


currently I'm doing Daniel Kehoe's Learn Ruby on Rails tutorial. One of the exercises is to send a contact form from the Contact page using Google's Gmail account.

However, when I sent the contact form, instead of getting an email in my mailbox, I'm getting this error:

"SMTP-AUTH requested but missing user name"

In my config/application.yml file, I set my Gmail username and password.

Does anyone have an idea what could be the problem?

thanks for your help,

Anthony


Solution

  • For Rails 4.0 (Rails 4.1 uses a secrets.yml file to set credentials):

    Check the file config/environments/development.rb, you should have this:

      config.action_mailer.smtp_settings = {
        address: "smtp.gmail.com",
        port: 587,
        domain: ENV["DOMAIN_NAME"],
        authentication: "plain",
        enable_starttls_auto: true,
        user_name: ENV["GMAIL_USERNAME"],
        password: ENV["GMAIL_PASSWORD"]
      }
      # ActionMailer Config
      config.action_mailer.default_url_options = { :host => 'localhost:3000' }
      config.action_mailer.delivery_method = :smtp
      config.action_mailer.raise_delivery_errors = true
      # Send email in development mode.
      config.action_mailer.perform_deliveries = true
    

    Try replacing ENV["GMAIL_USERNAME"] with your Gmail username.

    You can set ENV["GMAIL_USERNAME"] in your Unix shell. Or set it in the file config/application.yml. If the username contains any non-alpha characters, you may need to enclose it in quotes in the file config/application.yml.