I am following the learn Ruby on Rails book by Daniel Kehoe and when I try to send mail, I get the following error.
ArgumentError at /contacts An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.
The better errors gem points to UserMailer.contact_email(@contact).deliver
in the Contacts Controller.
I have done some research and prior to the error had followed the book's instruction on setting the environmental variables in my .bash_profile file.
Any help is greatly appreciated.
Update
As per the responses, thank you. I had already set the mail (to: )
def contact_email(contact)
@contact = contact
mail(to: Rails.application.secrets.owner_email, from: @contact.email, :subject => "Website Contact")
end
And I set the smtp settings:
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
}
Update 2
Thanks. Find secrets below :) I excluded the secret key base here
development:
email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
domain_name: example.com
mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
owner_email: <%= ENV["OWNER_EMAIL"] %>
secret_key_base: 'my secret key_base'
test:
secret_key_base: 'my secret key_base'
production:
email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
domain_name: <%= ENV["DOMAIN_NAME"] %>
mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
owner_email: <%= ENV["OWNER_EMAIL"] %>
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
to:
option to a valid email when callingmail()
in your mailer? – infused