aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/helpers/application_helper.rb3
-rw-r--r--app/helpers/mailer_helper.rb7
-rw-r--r--app/models/application_mailer.rb7
-rw-r--r--app/models/contact_mailer.rb12
-rw-r--r--app/views/contact_mailer/from_admin_message.rhtml2
-rw-r--r--config/environments/development.rb1
6 files changed, 26 insertions, 6 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 0520a8c77..df016a249 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -17,6 +17,9 @@ module ApplicationHelper
# Site-wide access to configuration settings
include ConfigHelper
+ # Useful for sending emails
+ include MailerHelper
+
# Copied from error_messages_for in active_record_helper.rb
def foi_error_messages_for(*params)
options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {}
diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb
new file mode 100644
index 000000000..c0a950d47
--- /dev/null
+++ b/app/helpers/mailer_helper.rb
@@ -0,0 +1,7 @@
+module MailerHelper
+ def contact_from_name_and_email
+ contact_name = MySociety::Config.get("CONTACT_NAME", 'Alaveteli')
+ contact_email = MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost')
+ return "#{contact_name} <#{contact_email}>"
+ end
+end
diff --git a/app/models/application_mailer.rb b/app/models/application_mailer.rb
index 80f0d7289..044006f7c 100644
--- a/app/models/application_mailer.rb
+++ b/app/models/application_mailer.rb
@@ -9,17 +9,12 @@
class ApplicationMailer < ActionMailer::Base
# Include all the functions views get, as emails call similar things.
helper :application
+ include MailerHelper
# This really should be the default - otherwise you lose any information
# about the errors, and have to do error checking on return codes.
self.raise_delivery_errors = true
- def contact_from_name_and_email
- contact_name = MySociety::Config.get("CONTACT_NAME", 'Alaveteli')
- contact_email = MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost')
- return "#{contact_name} <#{contact_email}>"
- end
-
def blackhole_email
MySociety::Config.get("BLACKHOLE_PREFIX", 'do-not-reply-to-this-address')+"@"+MySociety::Config.get("INCOMING_EMAIL_DOMAIN", "localhost")
end
diff --git a/app/models/contact_mailer.rb b/app/models/contact_mailer.rb
index 74c213c7a..800fe54e4 100644
--- a/app/models/contact_mailer.rb
+++ b/app/models/contact_mailer.rb
@@ -42,4 +42,16 @@ class ContactMailer < ApplicationMailer
}
end
+ # Send message to a user from the administrator
+ def from_admin_message(recipient_user, subject, message)
+ @from = contact_from_name_and_email
+ @recipients = recipient_user.name_and_email
+ @subject = subject
+ @body = {
+ :message => message,
+ :from_user => @from,
+ :recipient_user => recipient_user,
+ }
+ end
+
end
diff --git a/app/views/contact_mailer/from_admin_message.rhtml b/app/views/contact_mailer/from_admin_message.rhtml
new file mode 100644
index 000000000..bdb48d580
--- /dev/null
+++ b/app/views/contact_mailer/from_admin_message.rhtml
@@ -0,0 +1,2 @@
+<%= @message.strip %>
+
diff --git a/config/environments/development.rb b/config/environments/development.rb
index a1e8133a8..cfb727695 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -17,6 +17,7 @@ config.action_view.debug_rjs = true
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
+config.action_mailer.perform_deliveries = false
config.action_mailer.delivery_method = :sendmail # so is queued, rather than giving immediate errors
# Writes useful log files to debug memory leaks, of the sort where have