I keep getting error on "Send Mail" section on the Learn Ruby on Rails tutorial.
I have tried to clone https://github.com/RailsApps/learn-rails.git on my local machine but the issue is still here.
Below is my code:
user_mailer.rb
class UserMailer < ApplicationMailer
default from: "[email protected]"
def contact_email(contact)
@contact = contact
mail(to: Rails.application.secrets.owner_email, from: @contact.email, :subject => "Website Contact")
end
end
development.rb
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: Rails.application.secrets.domain_name,
authentication: "plain",
enable_starttls_auto: true,
user_name: Rails.application.secrets.email_provider_username,
password: Rails.application.secrets.email_provider_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
secrets.yml
development:
email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
domain_name: example.com
owner_email: <%= ENV["OWNER_EMAIL"] %>
I have also made sure that the environment variables were set up correctly on .bashrc file.
Any help will be greatly appreciated, and thank you in advance!
For development, you can use the letter opener gem. Once you send an email it'll automatically open in your default browser.
Add the following to the development section of your Gemfile.