From f89c1f16662962434e939d6e1a10d5768f239cb7 Mon Sep 17 00:00:00 2001 From: Roland Jesse Date: Sun, 15 Jan 2012 21:28:46 +0100 Subject: [PATCH] FogBugz #75: actually try to send some mail. --- app/controllers/birthdays_controller.rb | 19 +++++++++++++++---- app/mailers/user_mailer.rb | 5 +---- app/views/birthdays/do_mailing.html.erb | 1 + config/application.rb | 1 + config/environments/development.rb | 2 -- lib/development_mail_interceptor.rb | 6 ++++++ 6 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 lib/development_mail_interceptor.rb diff --git a/app/controllers/birthdays_controller.rb b/app/controllers/birthdays_controller.rb index a1aa018..e996185 100644 --- a/app/controllers/birthdays_controller.rb +++ b/app/controllers/birthdays_controller.rb @@ -6,15 +6,26 @@ class BirthdaysController < ApplicationController @birthdays = get_next_weeks_birthdays end - # curl --verbose --header "Accept: application/html" --header "Content-type: application/html" --request POST --data "" http://contactorama.dev/birthdays/do_mailing + # curl --verbose --header "Content-type: application/html" --request POST --data "" http://contactorama.dev/birthdays/do_mailing # wget --post-data '' http://contact-o-rama.de/birthdays/do_mailing # crontab: # 30 3 * * * wget --post-data '' http://contact-o-rama.de/birthdays/do_mailing def do_mailing birthdays = get_next_weeks_birthdays - birthdays.each do |bday| - logger.info "............< do_mailing: " + bday.firstname + " " + bday.lastname + " >.............." - UserMailer.next_weeks_birthday_notification(birthdays).deliver + logger.debug "birthdays.nil? = " + birthdays.nil?.to_s + "......" + unless birthdays.nil? + logger.debug "..... birthdays: " + birthdays.count.to_s + "......" + birthdays.each do |bday| + logger.info "............< do_mailing: " + bday.firstname + " " + bday.lastname + " >.............." + UserMailer.next_weeks_birthday_notification(birthdays).deliver + end + end + + logger.debug "........... Mailings done (or had none to do)" + respond_to do |format| + logger.debug ".... rendering...." + format.html { render :layout => false } + logger.debug ".... rendered ...." end end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index b7cf135..c6e3799 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -6,8 +6,5 @@ class UserMailer < ActionMailer::Base logger.debug "----------------< we don't send no email, yet >----------------------" @birthday_contacts = birthdays mail(:to => "contact-o-rama@gasbottle-county.eu", :subject => "Contact-o-Rama: Geburtstage in den nächsten 7 Tagen.") - birthdays.each do |contact| - - end - end + end end diff --git a/app/views/birthdays/do_mailing.html.erb b/app/views/birthdays/do_mailing.html.erb index e69de29..619c561 100644 --- a/app/views/birthdays/do_mailing.html.erb +++ b/app/views/birthdays/do_mailing.html.erb @@ -0,0 +1 @@ +Done. diff --git a/config/application.rb b/config/application.rb index 29e8103..804da37 100644 --- a/config/application.rb +++ b/config/application.rb @@ -14,6 +14,7 @@ module ContactORama # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W(#{config.root}/extras) + config.autoload_paths += Dir["#{config.root}/lib", "#{config.root}/lib/**/"] # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. diff --git a/config/environments/development.rb b/config/environments/development.rb index 23222ce..09f7e3d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -17,8 +17,6 @@ ContactORama::Application.configure do # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false - config.action_mailer.default_url_options = { :host => 'localhsot:3000' } - # Print deprecation notices to the Rails logger config.active_support.deprecation = :log diff --git a/lib/development_mail_interceptor.rb b/lib/development_mail_interceptor.rb new file mode 100644 index 0000000..ee0a38c --- /dev/null +++ b/lib/development_mail_interceptor.rb @@ -0,0 +1,6 @@ +class DevelopmentMailInterceptor + def self.delivering_email(message) + message.subject = "#{message.to} #{message.subject}" + message.to = "roland@gasbottle-county.eu" + end +end