Error "SMTP The address needs to send a message" in the tutorial
I keep getting an error in the Send Mail section of the Learn Ruby on Rails tutorial .
I tried to clone https://github.com/RailsApps/learn-rails.git on my local machine, but the problem is still here.
Below is my code:
user_mailer.rb
class UserMailer < ApplicationMailer
default from: "do-not-reply@example.com"
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 also made sure the environment variables were set correctly in the .bashrc file.
Any help would be greatly appreciated and thanks in advance!
source to share
I also had an identical problem. I tried everything: disabling 2-Step Verification (Google) before hard-coding my credentials into secrets.yml with zero success.
I used my outlook.com credentials and it worked great.
Note: This requires modifying development.rb
config.action_mailer.smtp_settings = {
address : "smtp.live.com"
# everything else is identical.
}
source to share
Setting for gmail
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:domain => "gmail.com",
:port => 587,
:user_name => "username",
:password => "password",
:authentication => :plain,
:enable_starttls_auto => true,
:openssl_verify_mode => 'none'
}
to make it true config.action_mailer.raise_delivery_errors = true
it will tell if any error has occurred.
Also try port 25
source to share