0

I am on Ch 20 of the Learn Rails tutorial 'Send Mail'. There is a create contact form and a notification email is supposed to be sent to my email address. I have set up configuration as per the book and the email is being generated correctly i the terminal log. however the email never sends to my email inbox. I am getting an internal server error. see below for details.

Completed 500 Internal Server Error in 30831ms



Net::OpenTimeout (execution expired):

app/controllers/contacts_controller.rb:10:in `create'

contacts_controller.rb

class ContactsController < ApplicationController

  def new
  @contact = Contact.new
  end

  def create
    @contact = Contact.new(secure_params)
    if @contact.valid?
      UserMailer.contact_email(@contact).deliver_now
      flash[:notice] = "Message sent from #{@contact.name}."
      redirect_to root_path
    else
      render :new
    end
  end

  private
    def secure_params
      params.require(:contact).permit(:name, :email, :content)
    end
end

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

i also have my email address set in the config/secrets.yml file like so :

owner_email: <%= ENV["my_email_address@*******.com"] %>

I have also added the following to my .bashrc file as per the early chater of the book about configuration:

export SENDGRID_USERNAME="user_name"
export SENDGRID_PASSWORD="password"
export MAILCHIMP_API_KEY="long_random_api_key_here"
export MAILCHIMP_LIST_ID="list_id_here"
export OWNER_EMAIL="**********@*********.com"

so as far as i see i have set everything up according to the tutorial but the mail is not sending. any ideas why?

Owen
  • 361
  • 1
  • 5
  • 16

1 Answers1

0

From the above share code description and log trace, it seems like mailer settings is not configured properly.

Note: You need to set the mailer settings based on the environment on which you are working(eg: development.rb)

Follow the below given link for the configuration of mailer settings:

http://guides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration

Rohan
  • 2,681
  • 1
  • 12
  • 18
  • my development.rb file is blank. however, the tutorial says nothing about this file. I have set up according to the tutorial. i seems i shouldnt have to do anything extra. – Owen Mar 13 '18 at 08:05
  • As I have gone thorugh the tutorial they have mentioned the mailer configuration settings in Chapter 13:Configure. – Rohan Mar 13 '18 at 08:42
  • i followed all the configurations settings. What i am finding confusing now is that in the configuration section we are told to place the settings in the .bashrc file and only use the config/secrets.yml file if that wont work. now the author seems to have changed to the secrets.yml file. saying that all the config variables should be in there. i am totally confused as to where i should be placing my variables. – Owen Mar 13 '18 at 09:08
  • config variables placement is based on the developer point of view, as these variables should not be there in the subversion repository and the secret information should not be there in code(hardcoded) as well, so prefer to keep them in files which are not in the transferred between environments using subversion repository or using ./bashrc file and then exporting these variables – Rohan Mar 13 '18 at 09:29
  • what about line 10 of my controller. it says there is a problem but doesnt specify. – Owen Mar 13 '18 at 10:35
  • it only signifies that line of controller to which the point of execution could not be returned , so the problem is with UserMailer which in turn is calling action_mailer. – Rohan Mar 13 '18 at 10:54
  • what could be the problem with my UserMailer? – Owen Mar 16 '18 at 06:32
  • the problem it seems as mentioned in the answer as well is in the action_mailer settings which is invoked when sending emails – Rohan Mar 19 '18 at 04:41