diff --git a/app/controllers/supporters_controller.rb b/app/controllers/supporters_controller.rb index cd1c36c..621899f 100644 --- a/app/controllers/supporters_controller.rb +++ b/app/controllers/supporters_controller.rb @@ -8,6 +8,7 @@ class SupportersController < ApplicationController def create @supporter = Supporter.new supporter_form_params.merge(language: I18n.locale) if !input_to_fast? && @supporter.save + SupporterMailer.welcome_email(@supporter).deliver_now redirect_to thanks_path else flash.now[:danger] = t '.timeout' if input_to_fast? diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..9aba772 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'markus@hanflegal.ch' + layout 'mailer' +end diff --git a/app/mailers/supporter_mailer.rb b/app/mailers/supporter_mailer.rb new file mode 100644 index 0000000..faa9bf3 --- /dev/null +++ b/app/mailers/supporter_mailer.rb @@ -0,0 +1,6 @@ +class SupporterMailer < ApplicationMailer + def welcome_email(supporter) + @supporter = supporter + mail(to: @supporter.email, subject: I18n.t('welcome_email.subject')) + end +end diff --git a/app/views/layouts/mailer.slim b/app/views/layouts/mailer.slim new file mode 100644 index 0000000..f2ac24f --- /dev/null +++ b/app/views/layouts/mailer.slim @@ -0,0 +1,6 @@ +doctype html +html + head + meta content=("text/html; charset=UTF-8") http-equiv="Content-Type" / + body style='padding: 20px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;' + = yield diff --git a/app/views/supporter_mailer/welcome_email.slim b/app/views/supporter_mailer/welcome_email.slim new file mode 100644 index 0000000..000cdbd --- /dev/null +++ b/app/views/supporter_mailer/welcome_email.slim @@ -0,0 +1,20 @@ +p + strong Hallo #{@supporter.first_name}, + +p Du bist nun ein Teil der Bewegung! + +p Wir informieren dich per E-Mail über die nächsten Schritte und kommen aktiv auf dich zu. Auf https://www.hanflegal.ch/initiative informieren wir über laufende Aktivitäten. + +p + b Was kannst du machen? + +p + ul + li Folge uns auf Facebook Facebook und Twitter + li Teile unser Projekt in den sozialen Medien mit dem Hashtag #ch420 + li Erzähle allen von unserem Vorhaben und bitte Sie mitzumachen + li Werde Mitglied beim Verein Legalize it! + +p + | Hanfige Grüsse, + em die Initianten diff --git a/config/environments/development.rb b/config/environments/development.rb index 0feba2e..b458e0b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -35,4 +35,9 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + + config.action_mailer.default_url_options = { host: 'localhost:3000' } + + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 } end diff --git a/config/environments/production.rb b/config/environments/production.rb index ff9675c..54a29b2 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -73,4 +73,17 @@ Rails.application.configure do # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new + + config.action_mailer.default_url_options = { host: 'ch420.herokuapp.com' } + + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + port: '587', + address: ENV['SMTP_HOST'], + user_name: ENV['SMTP_USER'], + password: ENV['SMTP_PASSWORD'], + domain: 'hanflegal.ch', + authentication: :plain, + enable_starttls_auto: true + } end diff --git a/config/locales/de.yml b/config/locales/de.yml index a831324..746edf2 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1,4 +1,7 @@ de: + welcome_email: + subject: Besten dank für deine Unterstützung! + support_type: signer: Ich unterschreibe eine Volksinitiative für die Legalisierung von Cannabis. supporter: Ich unterschreibe eine Volksinitiative für die Legalisierung von Cannabis und helfe aktiv Unterschriften in meiner Umgebung zu sammeln. diff --git a/spec/features/support_spec.rb b/spec/features/support_spec.rb index 0e9dc6c..cdf321f 100644 --- a/spec/features/support_spec.rb +++ b/spec/features/support_spec.rb @@ -20,7 +20,10 @@ feature 'Support announcement' do sleep 5 # Do a real sleep to have a real integration test + expect(ActionMailer::Base.deliveries.count).to eq 0 expect { click_button 'Unterstützung zusichern' }.to change { Supporter.count }.by(1) + expect(ActionMailer::Base.deliveries.count).to eq 1 + supporter = Supporter.find_by(email: 'blocher@blocher.ch') expect(supporter.coordinates).to eq [8.618589100000001, 47.2926304] expect(supporter.comments).to eq 'Test text' diff --git a/spec/mailers/previews/supporter_mailer_preview.rb b/spec/mailers/previews/supporter_mailer_preview.rb new file mode 100644 index 0000000..f8178a0 --- /dev/null +++ b/spec/mailers/previews/supporter_mailer_preview.rb @@ -0,0 +1,6 @@ +# Preview all emails at http://localhost:3000/rails/mailers/supporter_mailer +class SupporterMailerPreview < ActionMailer::Preview + def welcome + SupporterMailer.welcome_email(Supporter.first) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 16aefb5..0e2cc4a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,4 +44,8 @@ RSpec.configure do |config| config.after(:each) do Mongoid.purge! end + + config.before(:each) do + ActionMailer::Base.deliveries.clear + end end