Hi I’m trying to make a mailer for a contact us form. The email would be :from user@email.com and be :to my@email.com . Is this possible to do over SMTP in development? Does ActionMailer actually send the email from the users email account or is it just a fake email? The reason I want to use user@email.com as the sender is because I want it to be easy for me to just reply to that email directly.
I’m trying to use localhost and I’m receiving an error: Errno::ECONNREFUSED (Connection refused - connect(2)): I think it is because I haven’t set up the settings properly. Is it required to have a username/password on an actual gmail account for this email to be sent?
This is my settings right now (I didn’t have any username/password, so could this be the source of my error?):
ActionMailer::Base.smtp_settings = {
:address => '127.0.0.1',
:port => 25
}
controller:
def email
ContactMailer.contact_form(params).deliver
end
mailer:
class ContactMailer < ActionMailer::Base
default :to => "my@email.com"
def contact_form(sender)
@sender = sender
mail(:from => sender[:email], :subject => "Question from #{sender[:company] ? sender[:company] : "" }
- Contact Us")
end
end
views/contact_mailer/contact_mailer.text.erb:
We have been contacted by <%= @sender[:email] %>
FIXED
I added this line to my initializer:
ActionMailer::Base.delivery_method = :sendmail
Use Letter Opener for you development.