Commit a54164eb4cd47750a7fa329d46479279b4f62c55
1 parent
0c76dfbb
Exists in
master
and in
29 other branches
Some fixes when sending contact messages
added content_type text/html on mailer and HTML tags on message including environment contact_email on from and sender email on reply_to
Showing
3 changed files
with
50 additions
and
21 deletions
Show diff stats
app/models/contact.rb
@@ -23,9 +23,11 @@ class Contact < ActiveRecord::Base #WithoutTable | @@ -23,9 +23,11 @@ class Contact < ActiveRecord::Base #WithoutTable | ||
23 | 23 | ||
24 | class Sender < ActionMailer::Base | 24 | class Sender < ActionMailer::Base |
25 | def mail(contact) | 25 | def mail(contact) |
26 | + content_type 'text/html' | ||
26 | emails = contact.dest.notification_emails | 27 | emails = contact.dest.notification_emails |
27 | recipients emails | 28 | recipients emails |
28 | - from "#{contact.name} <#{contact.email}>" | 29 | + from "#{contact.name} <#{contact.dest.environment.contact_email}>" |
30 | + reply_to contact.email | ||
29 | if contact.sender | 31 | if contact.sender |
30 | headers 'X-Noosfero-Sender' => contact.sender.identifier | 32 | headers 'X-Noosfero-Sender' => contact.sender.identifier |
31 | end | 33 | end |
app/views/contact/sender/mail.rhtml
1 | -<%= _('This message was sent by %{sender} to %{target} on %{environment}.') % | ||
2 | - {:sender => @name, :target => @target, :environment => @environment} %> | ||
3 | -<%= _('Below here are the informations about the user who sent this message:')%> | ||
4 | -<ul> | ||
5 | - <li><%= content_tag('b', _('Name')+': ') + @name%></li> | ||
6 | - <li><%= content_tag('b', _('Email')+': ') + @email%></li> | ||
7 | - <% if @city || @state %> | ||
8 | - <li><%= content_tag('b', _('City and state')+': ') + (@city || '?')+'/'+(@state || '?') %></li> | ||
9 | - <% end %> | ||
10 | -</ul> | 1 | +<!DOCTYPE html> |
2 | +<html> | ||
3 | + <head> | ||
4 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | ||
5 | + </head> | ||
6 | + <body> | ||
7 | + <p><%= _('This message was sent by %{sender} to %{target} on %{environment}.') % | ||
8 | + {:sender => @name, :target => @target, :environment => @environment} %></p> | ||
9 | + <%= _('Information about the user who sent this message:')%> | ||
10 | + <ul> | ||
11 | + <li><%= content_tag('b', _('Name')+': ') + @name%></li> | ||
12 | + <li><%= content_tag('b', _('Email')+': ') + @email%></li> | ||
13 | + <% if @city || @state %> | ||
14 | + <li><%= content_tag('b', _('City and state')+': ') + (@city || '?')+'/'+(@state || '?') %></li> | ||
15 | + <% end %> | ||
16 | + </ul> | ||
17 | + <hr/> | ||
18 | + <%= content_tag('b', _('Message:')) %> | ||
19 | + <p><%= word_wrap(@message) %></p> | ||
11 | 20 | ||
12 | -<%= _('Message:') %> | ||
13 | -------------------------------------------------------------------------------- | ||
14 | -<%= word_wrap(@message) %> | ||
15 | -------------------------------------------------------------------------------- | 21 | + --<br/> |
22 | + <%= _('Greetings,') %><br/> | ||
23 | + <%= _('%s team.') % @environment %><br/> | ||
24 | + <%= @url %> | ||
25 | + </body> | ||
26 | +</html> | ||
16 | 27 | ||
17 | -<%= _('Greetings,') %> | ||
18 | - | ||
19 | --- | ||
20 | -<%= _('%s team.') % @environment %> | ||
21 | -<%= @url %> |
test/unit/contact_test.rb
@@ -22,7 +22,7 @@ class ContactTest < ActiveSupport::TestCase | @@ -22,7 +22,7 @@ class ContactTest < ActiveSupport::TestCase | ||
22 | should 'validates format of email only if not empty' do | 22 | should 'validates format of email only if not empty' do |
23 | contact = Contact.new | 23 | contact = Contact.new |
24 | contact.valid? | 24 | contact.valid? |
25 | - assert_match /^.* can't be blank$/, contact.errors[:email] | 25 | + assert_match(/^.* can't be blank$/, contact.errors[:email]) |
26 | end | 26 | end |
27 | 27 | ||
28 | should 'inicialize fields on instanciate' do | 28 | should 'inicialize fields on instanciate' do |
@@ -44,4 +44,25 @@ class ContactTest < ActiveSupport::TestCase | @@ -44,4 +44,25 @@ class ContactTest < ActiveSupport::TestCase | ||
44 | assert !c.deliver | 44 | assert !c.deliver |
45 | end | 45 | end |
46 | 46 | ||
47 | + should 'use sender name and environment contact_email on from' do | ||
48 | + ent = fast_create(Enterprise, :name => 'my enterprise', :identifier => 'myent') | ||
49 | + c = Contact.new(:name => 'john', :email => 'john@invalid.com', :subject => 'hi', :message => 'hi, all', :dest => ent) | ||
50 | + email = c.deliver | ||
51 | + assert_equal "#{c.name} <#{ent.environment.contact_email}>", email['from'].to_s | ||
52 | + end | ||
53 | + | ||
54 | + should 'add dest name on subject' do | ||
55 | + ent = fast_create(Enterprise, :name => 'my enterprise', :identifier => 'myent') | ||
56 | + c = Contact.new(:name => 'john', :email => 'john@invalid.com', :subject => 'hi', :message => 'hi, all', :dest => ent) | ||
57 | + email = c.deliver | ||
58 | + assert_equal "[#{ent.short_name(30)}] #{c.subject}", email['subject'].to_s | ||
59 | + end | ||
60 | + | ||
61 | + should 'add sender email on reply_to' do | ||
62 | + ent = fast_create(Enterprise, :name => 'my enterprise', :identifier => 'myent') | ||
63 | + c = Contact.new(:name => 'john', :email => 'john@invalid.com', :subject => 'hi', :message => 'hi, all', :dest => ent) | ||
64 | + email = c.deliver | ||
65 | + assert_equal c.email, email.reply_to.to_s | ||
66 | + end | ||
67 | + | ||
47 | end | 68 | end |