diff --git a/Gemfile b/Gemfile index d685db5f1..2a1f1429c 100644 --- a/Gemfile +++ b/Gemfile @@ -67,6 +67,8 @@ gem "font-awesome-rails" gem 'hashie' +gem 'mailjet' + group :test do gem 'capybara' gem 'factory_girl' diff --git a/Gemfile.lock b/Gemfile.lock index 70c65a821..abfada111 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -194,6 +194,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) @@ -446,6 +450,7 @@ DEPENDENCIES leaflet-markercluster-rails (~> 0.7.0) leaflet-rails logstasher + mailjet mina! openid_connect pg diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 000000000..68533b7dd --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "tps@apientreprise.fr" + layout 'mailer' +end diff --git a/app/mailers/welcome_mailer.rb b/app/mailers/welcome_mailer.rb new file mode 100644 index 000000000..b3542aecd --- /dev/null +++ b/app/mailers/welcome_mailer.rb @@ -0,0 +1,9 @@ +class WelcomeMailer < ApplicationMailer + def welcome_email user + + @user = user + + mail(from: "tps@apientreprise.fr", to: user.email, + subject: "Création de votre compte TPS") + end +end diff --git a/app/views/layouts/mailer.html.haml b/app/views/layouts/mailer.html.haml new file mode 100644 index 000000000..28739ee90 --- /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 000000000..f1d0cc898 --- /dev/null +++ b/app/views/layouts/mailer.text.haml @@ -0,0 +1 @@ += yield \ No newline at end of file diff --git a/app/views/welcome_mailer/welcome_email.text.erb b/app/views/welcome_mailer/welcome_email.text.erb new file mode 100644 index 000000000..59e4ef9e6 --- /dev/null +++ b/app/views/welcome_mailer/welcome_email.text.erb @@ -0,0 +1,15 @@ +Bienvenue sur la plateforme TPS + +Nous vous remercions de vous être inscrit sur TPS. Pour mémoire, voici quelques informations utiles : + + URL : https://tps.apientreprise.fr + Login : <%= @user.email %> + +Oubli de mot de passe, pas de problème : + + https://tps.apientreprise.fr/users/password/new + +Bonne journée, + +--- +L'équipe TPS - tps@apientreprise.fr \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 5fafdd184..6538124ce 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -36,6 +36,9 @@ Rails.application.configure do # Raises helpful error messages. config.assets.raise_runtime_errors = true + config.action_mailer.delivery_method = :mailjet + config.action_mailer.default_url_options = { :host => '{{ environment_mailer_host}}' } + # Raises error for missing translations # config.action_view.raise_on_missing_translations = true diff --git a/spec/mailers/welcome_mailer_spec.rb b/spec/mailers/welcome_mailer_spec.rb new file mode 100644 index 000000000..fa9ff057c --- /dev/null +++ b/spec/mailers/welcome_mailer_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe WelcomeMailer, type: :mailer do + describe ".welcome_email" do + let(:user) { create(:user) } + subject(:subject) { described_class.welcome_email(user) } + it { expect(subject.body).to match('https://tps.apientreprise.fr') } + it { expect(subject.body).to match('https://tps.apientreprise.fr/users/password/new') } + it { expect(subject.body).to match(user.email) } + it { expect(subject.body).to match('Bienvenue sur la plateforme TPS') } + it { expect(subject.body).to match('Nous vous remercions de vous être inscrit sur TPS. Pour mémoire, voici quelques informations utiles :')} + + it { expect(subject.subject).to eq("Création de votre compte TPS") } + end +end