Richlewis
Richlewis

Reputation: 15374

Actionmailer Rails 3

I have added a contact form to my site and am having a problem, when the message is sent I get my flash message, "successfully sent", however the email never arrives in my inbox. I am in development mode at the moment and my app/config file looks like this

   class Application < Rails::Application

   ActionMailer::Base.delivery_method = :smtp
   ActionMailer::Base.perform_deliveries = true
   ActionMailer::Base.raise_delivery_errors = true
   config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port    => 587,
    :domain  => "gmail.com",
    :user_name  => "[email protected]",
    :password   => "example",
    :authentication => :plain,
    :enable_starttls_auto => true
      }

     config.action_mailer.default_url_options = {
     :host => "gmail.com"
      }

My contact Controller is like this

      def new
       @message = Message.new
      end

     def create
     @message = Message.new(params[:message])
      if @message.valid?
      NotificationsMailer.new_message(@message).deliver
      redirect_to(root_path, :notice => "Message was successfully sent.")
     else
     flash.now.alert = "Please fill all fields."
     render :new
     end
    end 

     end

and finally my Notification Mailer

      class NotificationsMailer < ActionMailer::Base
      default :from => "[email protected]"
      default :to => "[email protected]"

     def new_message(message)
     @message = message
     if message.file
      attachment_name = message.file.original_filename
      attachments[attachment_name] = message.file.read
     end
     mail(:subject => "[[email protected]] #{message.subject}")
    end
     end

Am I missing anything obvious here as I have implemented this in another site which worked fine, just cant figure out what is going on

Any help appreciated

Upvotes: 0

Views: 578

Answers (1)

Angelo
Angelo

Reputation: 492

I know you set it in your app/config.rb, but I would ensure config.action_mailer.perform_deliveries isn't being overridden in your config/environments/development.rb

Upvotes: 1

Related Questions