Ruby On Rails - Contact form not sending email via localhost
Posted
by
anonymousxxx
on Stack Overflow
See other posts from Stack Overflow
or by anonymousxxx
Published on 2012-09-04T15:37:06Z
Indexed on
2012/09/04
15:38 UTC
Read the original article
Hit count: 201
similar problem Rails contact form not working
guides: https://github.com/thomasklemm/email_form_rails rails 3.2.x
app\models\message.rb
class Message
include ActiveAttr::Model
include ActiveModel::Validations
attribute :name
attribute :email
attribute :subject
attribute :body
attr_accessible :name, :email, :subject, :body
validates_presence_of :name
validates_presence_of :email
validates :email, email_format: { message: "is not looking like a valid email address"}
validates_presence_of :subject
validates_length_of :body, maximum: 500
end
app\mailers\contact_form.rb
class ContactForm < ActionMailer::Base
default from: "[email protected]"
default to: "[email protected]"
def email_form(message)
@message = message
mail subject: "#{message.subject} #{message.name}"
mail body: "#{message.body}"
end
end
development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mydomain.com",
:user_name => "[email protected]",
:password => "mypassword",
:authentication => :plain,
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = {
:host => "localhost:3000"
}
output in command
Started POST "/email" for 127.0.0.1 at 2012-09-04 22:10:40 +0700 Processing by HomeController#send_email_form as HTML Parameters: {"utf8"=>"v", "authenticity_token"=>"w39BLqCrjTMm4RRi/Sm5hZoEpcw46 npyRy/RS0h48x0=", "message"=>{"name"=>"anonymousxxx", "email"=>"[email protected]", "subject"=>"Test", "body"=>"send email"}, "commit"=>"Create Message"} Redirected to localhost:3000/home/contact Completed 302 Found in 1ms (ActiveRecord: 0.0ms)
but email (message) no receive my email,..
© Stack Overflow or respective owner