From 9f7f29f3271a34a0c907956031f79e3d11ba9e36 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Thu, 8 Oct 2015 19:16:33 -0500 Subject: [PATCH] mailjet mailers --- .rubocop.yml | 2 ++ Gemfile | 1 + Gemfile.lock | 17 +++++++++++++++++ app/controllers/oauths_controller.rb | 4 ++-- app/mailers/account_mailer.rb | 6 ++++++ app/mailers/application_mailer.rb | 4 ++++ .../account_mailer/activation_needed.html.haml | 4 ++++ app/views/layouts/mailer.html.haml | 3 +++ app/views/layouts/mailer.text.haml | 1 + config/application.rb | 1 + config/initializers/mailjet.rb | 5 +++++ test/mailers/account_mailer_test.rb | 7 +++++++ test/mailers/previews/account_mailer_preview.rb | 3 +++ 13 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 app/mailers/account_mailer.rb create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/views/account_mailer/activation_needed.html.haml create mode 100644 app/views/layouts/mailer.html.haml create mode 100644 app/views/layouts/mailer.text.haml create mode 100644 config/initializers/mailjet.rb create mode 100644 test/mailers/account_mailer_test.rb create mode 100644 test/mailers/previews/account_mailer_preview.rb diff --git a/.rubocop.yml b/.rubocop.yml index d801f02..13dc07f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -27,6 +27,7 @@ Style/StringLiterals: Metrics/AbcSize: Exclude: - db/migrate/**/* + - app/controllers/oauths_controller.rb Metrics/LineLength: Max: 95 @@ -39,3 +40,4 @@ Metrics/LineLength: Metrics/MethodLength: Exclude: - db/migrate/* + - app/controllers/oauths_controller.rb diff --git a/Gemfile b/Gemfile index 22ba1ac..1a3e445 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,7 @@ gem 'autoprefixer-rails', '~> 0.8' gem 'haml-rails', "~> 0.9" gem 'jquery-rails' gem 'json', '~> 1.8.3' +gem 'mailjet', '~> 1.1.0' gem 'mysql2', '~> 0.3.20' gem 'responders', '~> 2.1.0' gem 'sass-rails', '~> 5.0' diff --git a/Gemfile.lock b/Gemfile.lock index 60f80dc..33044c7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -63,6 +63,8 @@ GEM columnize (0.9.0) daemons (1.2.3) debug_inspector (0.0.2) + domain_name (0.5.25) + unf (>= 0.0.5, < 1.0.0) em-websocket (0.5.1) eventmachine (>= 0.12.9) http_parser.rb (~> 0.6.0) @@ -120,6 +122,8 @@ GEM haml (~> 4.0.0) nokogiri (~> 1.6.0) ruby_parser (~> 3.5) + http-cookie (1.0.2) + domain_name (~> 0.5) http_parser.rb (0.6.0) i18n (0.7.0) jquery-rails (4.0.5) @@ -136,6 +140,10 @@ GEM lumberjack (1.0.9) mail (2.6.3) mime-types (>= 1.16, < 3) + mailjet (1.1.0) + activesupport (>= 3.1.0) + rack (>= 1.4.0) + rest-client method_source (0.8.2) mime-types (2.6.1) mini_portile (0.6.2) @@ -150,6 +158,7 @@ GEM multipart-post (2.0.0) mysql2 (0.3.20) nenv (0.2.0) + netrc (0.10.3) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) notiffany (0.0.7) @@ -210,6 +219,10 @@ GEM ffi (>= 0.5.0) responders (2.1.0) railties (>= 4.2.0, < 5) + rest-client (1.8.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) rubocop (0.33.0) astrolabe (~> 1.3) parser (>= 2.2.2.5, < 3.0) @@ -262,6 +275,9 @@ GEM uglifier (2.7.2) execjs (>= 0.3.0) json (>= 1.8.0) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.1) web-console (2.2.1) activemodel (>= 4.0) binding_of_caller (>= 0.7.2) @@ -288,6 +304,7 @@ DEPENDENCIES haml_lint jquery-rails json (~> 1.8.3) + mailjet (~> 1.1.0) minitest-reporters mysql2 (~> 0.3.20) pry-byebug diff --git a/app/controllers/oauths_controller.rb b/app/controllers/oauths_controller.rb index bed511a..9495375 100644 --- a/app/controllers/oauths_controller.rb +++ b/app/controllers/oauths_controller.rb @@ -14,8 +14,8 @@ class OauthsController < ApplicationController else begin @user = create_from(provider) - # NOTE: this is the place to add '@user.activate!' - # if you are using user_activation submodule + # NOTE: this is the place to add '@user.activate!' if you + # are using user_activation submodule reset_session # protect from session fixation attack auto_login(@user) diff --git a/app/mailers/account_mailer.rb b/app/mailers/account_mailer.rb new file mode 100644 index 0000000..569df6e --- /dev/null +++ b/app/mailers/account_mailer.rb @@ -0,0 +1,6 @@ +class AccountMailer < ApplicationMailer + def activation_needed + @blarg = "This was blarg" + mail(to: 'markamoser+test@gmail.com', subject: 'Activate me please!') + end +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..e21ed33 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: ENV['default_mail_from'] + layout 'mailer' +end diff --git a/app/views/account_mailer/activation_needed.html.haml b/app/views/account_mailer/activation_needed.html.haml new file mode 100644 index 0000000..eacb9f0 --- /dev/null +++ b/app/views/account_mailer/activation_needed.html.haml @@ -0,0 +1,4 @@ +!!! +%h3 Activate me please + +%p and then: #{@blarg} diff --git a/app/views/layouts/mailer.html.haml b/app/views/layouts/mailer.html.haml new file mode 100644 index 0000000..28739ee --- /dev/null +++ b/app/views/layouts/mailer.html.haml @@ -0,0 +1,3 @@ +%hmtl + %body + = yield \ No newline at end of file diff --git a/app/views/layouts/mailer.text.haml b/app/views/layouts/mailer.text.haml new file mode 100644 index 0000000..f1d0cc8 --- /dev/null +++ b/app/views/layouts/mailer.text.haml @@ -0,0 +1 @@ += yield \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index ceb147f..3f21dfe 100644 --- a/config/application.rb +++ b/config/application.rb @@ -21,5 +21,6 @@ module SmsPager # Do not swallow errors in after_commit/after_rollback callbacks. config.active_record.raise_in_transactional_callbacks = true + config.action_mailer.delivery_method = :mailjet end end diff --git a/config/initializers/mailjet.rb b/config/initializers/mailjet.rb new file mode 100644 index 0000000..2481ab2 --- /dev/null +++ b/config/initializers/mailjet.rb @@ -0,0 +1,5 @@ +Mailjet.configure do |config| + config.api_key = ENV['mailjet_key'] + config.secret_key = ENV['mailjet_secret'] + config.default_from = ENV['default_mail_from'] +end diff --git a/test/mailers/account_mailer_test.rb b/test/mailers/account_mailer_test.rb new file mode 100644 index 0000000..f5d6e54 --- /dev/null +++ b/test/mailers/account_mailer_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class AccountMailerTest < ActionMailer::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/mailers/previews/account_mailer_preview.rb b/test/mailers/previews/account_mailer_preview.rb new file mode 100644 index 0000000..9a25e39 --- /dev/null +++ b/test/mailers/previews/account_mailer_preview.rb @@ -0,0 +1,3 @@ +# Preview all emails at http://localhost:3000/rails/mailers/account_mailer +class AccountMailerPreview < ActionMailer::Preview +end