Permalink
Browse files

Add config for notifications from email address & requiring name and/…

…or subject.
  • Loading branch information...
1 parent 5bdac6d commit a13cf0ffddc9667daa71dfc43813aa40fca8898d @JDutil committed Feb 25, 2012
View
@@ -2,3 +2,4 @@
--format=nested
--backtrace
--profile
+--order random
View
@@ -1,3 +1,11 @@
+*ContactUs 0.2.0 (February 25th 2012)*
+
+* Added ContactUs.mailer_from setting in order to send from verified address, which is better practice than pretending the email is from the user. [Jeff Dutil]
+
+* Added ContactUs.require_name setting in order to ask for the name with the contact form. [Jeff Dutil]
+
+* Added ContactUs.require_subject setting in order to for the subject with the contact form. [Jeff Dutil]
+
*ContactUs 0.1.5 (January 6th, 2012)*
* Added Chinese zh locale [kinopyo]
View
@@ -38,9 +38,29 @@ Change to the email address you would like to receive the form submissions at fo
config.mailer_to = "contact@yourdomain.com"
+By default the emails from field will be the email entered by the user to easily reply, but this may not be allowed if your required to verify your sending email addresses.
+You may also specify an email address for the notification emails from field:
+
+ config.mailer_from = "dontreply@yourdomain.com"
+
+## UPGRADING
+
+When upgrading from 0.1.x to 0.2.x you should rerun the install generator to install the new settings, views, and locale updates:
+
+ $ bundle exec rake contact_us:install
+
+Or you may run the generators for each specific component you would like to update, which is quite useful when upgrading during patch releases for example from 0.2.0 to 0.2.1:
+
+ $ bundle exec rake contact_us:copy_locales
+ $ bundle exec rake contact_us:copy_views
+
## CONFIGURATION
-The generator copies the view files to `app/views/contact_us`, and you can customize them to suit your needs.
+The generator copies the view files to `app/views/contact_us`, and you can customize them to suit your needs. If you would like to add a name or subject field to the form you may simply
+set the options to true within the contact_us initializer located at `config/initializers/contact_us.rb`:
+
+ config.name = true
+ config.subject = true
You may also update your locales under `config/locales/contact_us.en.yml` or create your own. Please feel free to submit your own locales so that other users will hopefully find this gem more useful.
@@ -78,6 +98,5 @@ Here are some ways *you* can contribute:
## TODO
* Add new language translations
-* Make requested configurations in branches, and document how to reference within your Gemfile rather than the version. Configurations todo: with name, with subject, with name & subject
Copyright (c) 2011 Jeff Dutil, released under the [MIT license](https://github.com/jdutil/contact_us/tree/master/MIT-LICENSE).
@@ -1,9 +1,9 @@
class ContactUs::ContactMailer < ActionMailer::Base
def contact_email(contact)
- @message = contact.message
+ @contact = contact
- mail :from => contact.email,
- :subject => t('contact_us.contact_mailer.contact_email.subject', :email => contact.email),
+ mail :from => (ContactUs.mailer_from || contact.email),
+ :subject => (ContactUs.require_subject ? @contact.subject : t('contact_us.contact_mailer.contact_email.subject', :email => contact.email)),
:to => ContactUs.mailer_to
end
end
@@ -2,11 +2,13 @@ class ContactUs::Contact
include ActiveModel::Conversion
include ActiveModel::Validations
- attr_accessor :email, :message
+ attr_accessor :email, :message, :name, :subject
validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i },
:presence => true
validates :message, :presence => true
+ validates :name, :presence => {:if => Proc.new{ContactUs.require_name}}
+ validates :subject, :presence => {:if => Proc.new{ContactUs.require_subject}}
def initialize(attributes = {})
attributes.each do |key, value|
@@ -1,3 +1,3 @@
-<p><%= @message %></p>
+<p><%= @contact.message %></p>
<p>---------------------</p>
-<p><%= t('.sent_by_contact_form') %></p>
+<p><%= ContactUs.require_name ? t('.sent_by_name', :email => @contact.email, :name => @contact.name) : t('.sent_by_contact_form', :email => @contact.email) %></p>
@@ -1,4 +1,4 @@
-<%= @message %>
+<%= @contact.message %>
-------------------------------------
-<%= t('.sent_by_contact_form') %>
+<%= ContactUs.require_name ? t('.sent_by_name', :email => @contact.email, :name => @contact.name) : t('.sent_by_contact_form', :email => @contact.email) %>
@@ -1,6 +1,8 @@
<h2><%= t('.contact_us') %></h2>
<%= semantic_form_for @contact, :url => contacts_path do |f| %>
+ <%= f.input :name, :label => t('.name') if ContactUs.require_name %>
<%= f.input :email, :label => t('.email') %>
+ <%= f.input :subject, :label => t('.subject') if ContactUs.require_subject %>
<%= f.input :message, :as => :text, :label => t('.message') %>
<%= f.commit_button t('.submit'), :button_html => { :alt => t('.submit'), :id => 'contact_us_contact_submit', :title => t('.submit') } %>
<% end %>
@@ -5,13 +5,16 @@ de:
contact_us:
contact_mailer:
contact_email:
- sent_by_contact_form: "Gesendet durch das Kontaktformular."
+ sent_by_contact_form: "Gesendet durch das Kontaktformular. %{email}"
+ sent_by_name: "Sent by %{name} from %{email}"
subject: "Contact Us message from %{email}"
contacts:
new:
contact_us: "Kontaktiere Uns"
email: "Email"
message: "Nachricht"
+ name: "Name"
+ subject: "Subject"
submit: "Abschicken"
notices:
error: "Beide Felder müssen ausgefüllt werden."
@@ -5,13 +5,16 @@ en:
contact_us:
contact_mailer:
contact_email:
- sent_by_contact_form: "Sent by contact form."
+ sent_by_contact_form: "Sent by contact form from %{email}"
+ sent_by_name: "Sent by %{name} from %{email}"
subject: "Contact Us message from %{email}"
contacts:
new:
contact_us: "Contact Us"
email: "Email"
message: "Message"
+ name: "Name"
+ subject: "Subject"
submit: "Submit"
notices:
error: "You must enter both fields."
@@ -5,13 +5,16 @@ es:
contact_us:
contact_mailer:
contact_email:
- sent_by_contact_form: "Enviado por el formulario de contacto."
+ sent_by_contact_form: "Enviado por el formulario de contacto. %{email}"
+ sent_by_name: "Sent by %{name} from %{email}"
subject: "Contact Us message from %{email}"
contacts:
new:
contact_us: "Contactanos"
email: "Email"
message: "Mensaje"
+ name: "Name"
+ subject: "Subject"
submit: "Enviar"
notices:
error: "Debes de ingresar ambos campos."
@@ -5,13 +5,16 @@ it:
contact_us:
contact_mailer:
contact_email:
- sent_by_contact_form: "Inviato dal formato di contatto."
+ sent_by_contact_form: "Inviato dal formato di contatto. %{email}"
+ sent_by_name: "Sent by %{name} from %{email}"
subject: "Contact Us message from %{email}"
contacts:
new:
contact_us: "Contattaci"
email: "Email"
message: "Messaggio"
+ name: "Name"
+ subject: "Subject"
submit: "Inviare"
notices:
error: "Devi inserire entrambi i campi."
@@ -5,13 +5,16 @@ pt-BR:
contact_us:
contact_mailer:
contact_email:
- sent_by_contact_form: "Enviado pelo formulário de contato."
+ sent_by_contact_form: "Enviado pelo formulário de contato. %{email}"
+ sent_by_name: "Sent by %{name} from %{email}"
subject: "Contact Us message from %{email}"
contacts:
new:
contact_us: "Contate-nos"
email: "Email"
message: "Messagem"
+ name: "Name"
+ subject: "Subject"
submit: "Enviar"
notices:
error: "Você deve preencher os campos."
@@ -5,13 +5,16 @@ zh:
contact_us:
contact_mailer:
contact_email:
- sent_by_contact_form: "由contact form发送。"
+ sent_by_contact_form: "由contact form发送。 %{email}"
+ sent_by_name: "Sent by %{name} from %{email}"
subject: "Contact Us message from %{email}"
contacts:
new:
contact_us: "联系我们"
email: "邮箱"
message: "消息"
+ name: "Name"
+ subject: "Subject"
submit: "发送"
notices:
error: "请正确输入邮箱与信息。"
View
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "capybara", "~> 1.1"
s.add_development_dependency "rspec-rails", "~> 2.8"
+ s.add_development_dependency "shoulda-matchers", "~> 1.0"
s.add_development_dependency "simplecov", "~> 0.6"
s.add_development_dependency "sqlite3", "~> 1.3.5"
View
@@ -1,9 +1,18 @@
module ContactUs
require 'contact_us/engine'
-
- # Address to send ContactUs e-mails.
+
+ # Address ContactUs email notifications are sent from.
+ mattr_accessor :mailer_from
+
+ # Address to send ContactUs email notifications to.
mattr_accessor :mailer_to
+ # Enable or Disable name field.
+ mattr_accessor :require_name
+
+ # Enable or Disable subject field.
+ mattr_accessor :require_subject
+
# Default way to setup ContactUs. Run rake contact_us:install to create
# a fresh initializer with all configuration values.
def self.setup
@@ -1,6 +1,22 @@
# Use this hook to configure contact mailer.
ContactUs.setup do |config|
+
# ==> Mailer Configuration
- # Configure the e-mail address which will be shown in ContactMailer.
+
+ # Configure the e-mail address which email notifications should be sent from. If emails must be sent from a verified email address you may set it here.
+ # Example:
+ # config.mailer_from = "contact@please-change-me.com"
+ config.mailer_from = nil
+
+ # Configure the e-mail address which should receive the contact form email notifications.
config.mailer_to = "contact@please-change-me.com"
+
+ # ==> Form Configuration
+
+ # Configure the form to ask for the users name.
+ config.require_name = false
+
+ # Configure the form to ask for a subject.
+ config.require_subject = false
+
end
@@ -1,24 +0,0 @@
-require 'spec_helper'
-
-describe ContactUs do
-
- it "should be valid" do
- ContactUs.should be_a(Module)
- end
-
- describe 'setup block' do
- it 'should yield self' do
- ContactUs.setup do |config|
- ContactUs.should eql(config)
- end
- end
- end
-
- describe 'mailer_to' do
- it 'should be configurable' do
- ContactUs.mailer_to = "contact@please-change-me.com"
- ContactUs.mailer_to.should eql("contact@please-change-me.com")
- end
- end
-
-end
Oops, something went wrong. Retry.

0 comments on commit a13cf0f

Please sign in to comment.