contact.rb
1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Contact < ActiveRecord::Base #WithoutTable
tableless :columns => [
[:name, :string],
[:subject, :string],
[:message, :string],
[:email, :string],
[:state, :string],
[:city, :string],
[:receive_a_copy, :boolean]
]
attr_accessor :dest
attr_accessor :sender
N_('Subject'); N_('Message'); N_('City and state'); N_('e-Mail'); N_('Name')
validates_presence_of :subject, :email, :message, :name
validates_format_of :email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|o| !o.email.blank?})
def deliver
return false unless self.valid?
Contact::Sender.deliver_mail(self)
end
class Sender < ActionMailer::Base
def mail(contact)
content_type 'text/html'
emails = contact.dest.notification_emails
recipients emails
from "#{contact.name} <#{contact.dest.environment.contact_email}>"
reply_to contact.email
if contact.sender
headers 'X-Noosfero-Sender' => contact.sender.identifier
end
if contact.receive_a_copy
cc "#{contact.name} <#{contact.email}>"
end
subject "[#{contact.dest.short_name(30)}] " + contact.subject
body :name => contact.name,
:email => contact.email,
:city => contact.city,
:state => contact.state,
:message => contact.message,
:environment => contact.dest.environment.name,
:url => url_for(:host => contact.dest.environment.default_hostname, :controller => 'home'),
:target => contact.dest.name
end
end
end