ActionMailer will not send mail?

I am trying to create a simple contact_us page in my dev environment where a user can submit a request using the form I created. I have ActiveMailer, and the Contact / Control / View model is all set up, but it seems to be working incorrectly. Any ideas? My log displays mail sending.

Actionmailer

class ContactConfirmation < ActionMailer::Base
  default from: "from@example.com"

  def receipt(contact)
    @contact = contact

    mail to: 'myname@example.com',
      subject: contact.subject
  end
end

Receipt

<%= @contact.first_name %> <%= @contact.last_name %>

Writes:

<%= @contact.description %>

ContactsController

class ContactsController < ApplicationController

  def new
    @contact = Contact.new
  end

  def create
    @contact = Contact.new(contact_params)
    if @contact.submit_contact_info
      redirect_to users_path, notice: 'Submission successful. Somebody will get back to you shortly.'
    else
      render :new
    end
  end

  protected

  def contact_params
    params.require(:contact).permit(:first_name, :last_name, :email, :subject, :description)
  end
end

Contact Model

class Contact < ActiveRecord::Base
  validates_presence_of :email
  validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
  validates_presence_of :subject
  validates_presence_of :description
  validates_presence_of :first_name
  validates_presence_of :last_name

  def submit_contact_info
    if save
      ContactConfirmation.receipt(self).deliver
      return true
    end
  end
end

Contact form displayed in contacts / new.html.erb

<%= simple_form_for @contact do |f| %>
  <%= f.input :first_name %>
  <%= f.input :last_name %>
  <%= f.input :email %>
  <%= f.input :subject %>
  <%= f.input :description, as: :text %>
  <%= f.submit 'Submit Contact Form' %>
<% end %>

In the Initializers folder, I have a smtp.rb file:

if Rails.env.development?
  ActionMailer::Base.delivery_method = :smtp
  ActionMailer::Base.smtp_settings = {
    address: "localhost",
    port: 1025
  }
end

After changing my configuration, we now get the following error on ContactConfirmation.receipt(self).deliver:

Errno :: ECONNREFUSED in ContactsController # create Connection refused - connect (2)

def submit_contact_info
    if save
      ContactConfirmation.receipt(self).deliver
      return true
    end
  end
+4
source share
1

, :

, , . , :

//development.rb

config.action_mailer.raise_delivery_errors = true 
config.action_mailer.perform_deliveries = true

, . , Connection refused, , . mailcatcher (, 1025), mailcatcher. , localhost:1080.

+5

All Articles