In my rails app I have a contact form that lets users send an email to my gmail account.
Problem 1
I'm using the same gmail account to send the emails as I'm using to receive them, and thus when I click the 'reply' button, gmail sets-up a new email to myself....
My mailer looks like this:
class Notification < ActionMailer::Base
default :to => ENV['GMAIL_USER']
def hello(contact)
mail(
:from => contact[:email],
:return_path => contact[:email],
:subject => "[My Website] << #{contact[:subject]}",
:body => contact[:body] )
end
end
I was under the impression that setting :return_path => contact[:email]
would ensure that gmail would know who to send the reply to.... Obviously I'm wrong there. Anyone know how to fix this?
Problem 2
Most action_mailer tutorials out there would have me set up my mail method using :from => contact.email
as opposed to :from => contact[:email]
like so:
def hello(contact)
@contact = contact
mail(
:from => contact.email,
:return_path => contact.email,
:subject => "[My Website] << #{contact.subject}",
:body => contact.body
)
end
But when I do it this way, I get the following error message:
undefined method `email' for #<ActiveSupport::HashWithIndifferentAccess:0xdde82f0>
Anyone know what the recommended approach isn't working for me.
Appendage
FWIW, in-case it helps, my contact model extends a tabless active_record model as I don't want to use the database but do want to have valiations so it looks like this:
#contact.rb
class Contact < Tabless
column :name, :string
column :email, :string
column :body, :text
column :subject, :string
# validations go here
end
# tabless.rb
class Tabless < ActiveRecord::Base
# create an array of columns
def self.columns()
@columns ||= [];
end
# add new column to columns array
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s,
default,
sql_type.to_s,
null)
end
# override the save method to prevent exceptions
def save(validate = true)
validate ? valid? : true
end
end