Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat send email #134

Merged
merged 11 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def create
if user.valid?
user.lock_access!
user.save
UserMailer.with(user: user).uuid_created.deliver_now
else
return head 406 # Not acceptable
end
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
default from: Rails.application.credentials.email_from
layout 'mailer'
end
7 changes: 7 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class UserMailer < ApplicationMailer
def uuid_created
@user = params[:user]

mail(to: @user.email, subject: I18n.t('mail.uuid_subject'))
end
end
1 change: 1 addition & 0 deletions app/views/user_mailer/uuid_created.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= I18n.t 'mail.uuid_created' %><%= @user.uuid %>
1 change: 1 addition & 0 deletions app/views/user_mailer/uuid_created.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= I18n.t 'mail.uuid_created' %><%= @user.uuid %>
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false


config.action_mailer.delivery_method = :smtp

config.action_mailer.perform_caching = false

# Print deprecation notices to the Rails logger.
Expand Down
2 changes: 2 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@

config.action_mailer.perform_caching = false

config.action_mailer.delivery_method = :smtp

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
Expand Down
9 changes: 9 additions & 0 deletions config/initializers/mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ActionMailer::Base.smtp_settings = {
address: Rails.application.credentials.smtp_address,
port: Rails.application.credentials.smtp_port,
domain: Rails.application.credentials.smtp_domain,
user_name: Rails.application.credentials.smtp_user_name,
password: Rails.application.credentials.smtp_password,
authentication: Rails.application.credentials.smtp_authentication,
enable_starttls_auto: Rails.application.credentials.smtp_enable_starttls_auto
}
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@
# available at http://guides.rubyonrails.org/i18n.html.

en:
hello: "Hello world"
mail:
uuid_subject: "Your PIA account"
uuid_created: "Your PIA account was created, your uuid is: "
4 changes: 4 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fr:
mail:
uuid_subject: "Votre compte PIA"
uuid_created: "Votre compte PIA a été créé, voilà votre uuid: "
4 changes: 4 additions & 0 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
class UserMailerPreview < ActionMailer::Preview

end
7 changes: 7 additions & 0 deletions test/mailers/user_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class UserMailerTest < ActionMailer::TestCase
# test "the truth" do
# assert true
# end
end