diff --git a/Gemfile b/Gemfile index 72490dbfc..bc9a0ca9e 100644 --- a/Gemfile +++ b/Gemfile @@ -78,7 +78,7 @@ gem 'hoptoad_notifier' gem 'newrelic_rpm', :require => false #mail -gem 'messagebus_ruby_api', :git => 'https://github.com/messagebus/messagebus_ruby_api.git' +gem 'messagebus_ruby_api', '0.4.0' # tags diff --git a/Gemfile.lock b/Gemfile.lock index 2bfff4f17..499f186cb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -56,12 +56,6 @@ GIT addressable (>= 2.1.1) eventmachine (>= 0.12.9) -GIT - remote: https://github.com/messagebus/messagebus_ruby_api.git - revision: 02b3d04730f3a72f636c0b4ddbbcd660bba6a75e - specs: - messagebus_ruby_api (0.4.8) - GEM remote: http://rubygems.org/ specs: @@ -251,6 +245,7 @@ GEM i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) + messagebus_ruby_api (0.4.0) mime-types (1.16) mini_magick (3.2) subexec (~> 0.0.4) @@ -511,7 +506,7 @@ DEPENDENCIES json (= 1.4.6) jwt (= 0.1.3) linecache (= 0.43) - messagebus_ruby_api! + messagebus_ruby_api (= 0.4.0) mini_magick (= 3.2) mobile-fu mock_redis diff --git a/config/application.yml.example b/config/application.yml.example index 71902cad8..e8b619857 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -114,7 +114,7 @@ defaults: &defaults smtp_port: '587' # This chooses which mailer should be used. 'smtp' for a smtp - # connection or 'sendmail' to use the sendmail binary. + # connection or 'sendmail' to use the sendmail binary, or messagebus, to use the messagebus service mailer_method: 'smtp' # The path to the sendmail binary. Ignored if mailer_method is not set to sendmail diff --git a/config/initializers/mailer_config.rb b/config/initializers/mailer_config.rb index 2f5a3d366..c22d3815d 100644 --- a/config/initializers/mailer_config.rb +++ b/config/initializers/mailer_config.rb @@ -5,36 +5,42 @@ require File.join(Rails.root, 'lib/messagebus/mailer') Diaspora::Application.configure do config.action_mailer.default_url_options = {:host => AppConfig[:pod_uri].authority } - # unless Rails.env == 'test' || AppConfig[:mailer_on] != true - # if AppConfig[:mailer_method] == "sendmail" - # config.action_mailer.delivery_method = :sendmail - # config.action_mailer.sendmail_settings = { - # :location => AppConfig[:sendmail_location] - # } - # else - # config.action_mailer.delivery_method = :smtp - # if AppConfig[:smtp_authentication] == "none" - # config.action_mailer.smtp_settings = { - # :address => AppConfig[:smtp_address], - # :port => AppConfig[:smtp_port], - # :domain => AppConfig[:smtp_domain], - # :enable_starttls_auto => false, - # :openssl_verify_mode => AppConfig[:smtp_openssl_verify_mode] - # } - # else - # config.action_mailer.smtp_settings = { - # :address => AppConfig[:smtp_address], - # :port => AppConfig[:smtp_port], - # :domain => AppConfig[:smtp_domain], - # :authentication => AppConfig[:smtp_authentication], - # :user_name => AppConfig[:smtp_username], - # :password => AppConfig[:smtp_password], - # :enable_starttls_auto => AppConfig[:smtp_starttls_auto], - # :openssl_verify_mode => AppConfig[:smtp_openssl_verify_mode] - # } - # end - # end - # end - config.action_mailer.delivery_method = Messagebus::Mailer.new('986071AEF15FBE380E75A9805C77E733') + unless Rails.env == 'test' || AppConfig[:mailer_on] != true + if AppConfig[:mailer_method] == 'messagebus' + if AppConfig[:messagebus_api_key].present? + config.action_mailer.delivery_method = Messagebus::Mailer.new(AppConfig[:messagebus_api_key]) + else + puts "You need to set your messagebus api key if you are going to use the message bus service. no mailer is now configured" + end + elsif AppConfig[:mailer_method] == "sendmail" + config.action_mailer.delivery_method = :sendmail + config.action_mailer.sendmail_settings = { + :location => AppConfig[:sendmail_location] + } + else + config.action_mailer.delivery_method = :smtp + if AppConfig[:smtp_authentication] == "none" + config.action_mailer.smtp_settings = { + :address => AppConfig[:smtp_address], + :port => AppConfig[:smtp_port], + :domain => AppConfig[:smtp_domain], + :enable_starttls_auto => false, + :openssl_verify_mode => AppConfig[:smtp_openssl_verify_mode] + } + else + config.action_mailer.smtp_settings = { + :address => AppConfig[:smtp_address], + :port => AppConfig[:smtp_port], + :domain => AppConfig[:smtp_domain], + :authentication => AppConfig[:smtp_authentication], + :user_name => AppConfig[:smtp_username], + :password => AppConfig[:smtp_password], + :enable_starttls_auto => AppConfig[:smtp_starttls_auto], + :openssl_verify_mode => AppConfig[:smtp_openssl_verify_mode] + } + end + end + end + end diff --git a/lib/messagebus/mailer.rb b/lib/messagebus/mailer.rb index 72ea03241..fab226332 100644 --- a/lib/messagebus/mailer.rb +++ b/lib/messagebus/mailer.rb @@ -2,7 +2,7 @@ module Messagebus class Mailer def initialize(api_key) - @client = MessagebusRubyApi::Client.new(api_key) + @client = MessagebusRubyApi::Client.new(AppConfig[:messagebus_api_key]) end attr_accessor :settings @@ -18,7 +18,7 @@ module Messagebus private def deliver(message) - puts "dslkfjasd;lfkjasd;lkfjasd;lkfjasd;lkfjasd;lfjkasd;lkfjasd;lfkjasd;lfkjasd;lkfjas;ldkfj;alsdkjf;lasdjkf;lasdkjf;alsdjkfls" + # here we want = {:fromEmail => message['from'].to_s} @client.common_info = {:fromEmail => message.from.first} message.to.each do |addressee| m = {:toEmail => addressee, :subject => message.subject} @@ -40,7 +40,5 @@ module Messagebus end end - end - end