class Inquiry
extend ActiveModel::Naming
include ActiveModel::Conversion
include ActiveModel::Validations
include ActionView::Helpers::TextHelper
attr_accessor :name, :email, :residence, :service
validates :residence,
:presence => true
validates :name,
:presence => true
validates :email,
:format => { :with => /\b[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}\z/ },
:presence => true
validates :service,
:presence => true
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def deliver
return false unless valid?
Pony.mail({
:from => %("#{name}" <#{email}>),
:subject => "subject",
:body => %("#{residence}" "#{name}" <#{email}> "#{service}")
})
end
def persisted?
false
end
end
Pony.options = {
:via => :smtp,
:via_options => {
:port => '587',
:enable_starttls_auto => true,
:user_name => ENV["GMAIL_USERNAME"],
:password => ENV["GMAIL_PASSWORD"],
:authentication => :login, # :plain, :login, :cram_md5, no auth by default
:domain => "localhost.localdomain" # the HELO domain provided by the client to the server
}
}