Skip to content

Commit

Permalink
Merge pull request #60 from adnjoo/mailgun
Browse files Browse the repository at this point in the history
mailgun
  • Loading branch information
adnjoo authored Oct 22, 2024
2 parents 343d2d9 + f3067f8 commit 39e87ca
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ gem "tailwindcss-rails", "~> 3.0"
gem "devise", "~> 4.9"

gem "stripe", "~> 13.0"

gem "mailgun-ruby", "~> 1.2"
17 changes: 17 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,14 @@ GEM
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
domain_name (0.6.20240107)
drb (2.2.1)
erubi (1.13.0)
globalid (1.2.1)
activesupport (>= 6.1)
http-accept (1.7.0)
http-cookie (1.0.7)
domain_name (~> 0.5)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
importmap-rails (2.0.3)
Expand All @@ -133,8 +137,14 @@ GEM
net-imap
net-pop
net-smtp
mailgun-ruby (1.2.15)
rest-client (>= 2.0.2)
marcel (1.0.4)
matrix (0.4.2)
mime-types (3.6.0)
logger
mime-types-data (~> 3.2015)
mime-types-data (3.2024.1001)
mini_mime (1.1.5)
minitest (5.25.1)
msgpack (1.7.3)
Expand All @@ -147,6 +157,7 @@ GEM
timeout
net-smtp (0.5.0)
net-protocol
netrc (0.11.0)
nio4r (2.7.3)
nokogiri (1.16.7-aarch64-linux)
racc (~> 1.4)
Expand Down Expand Up @@ -219,6 +230,11 @@ GEM
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.3.8)
rubocop (1.67.0)
json (~> 2.3)
Expand Down Expand Up @@ -318,6 +334,7 @@ DEPENDENCIES
devise (~> 4.9)
importmap-rails
jbuilder
mailgun-ruby (~> 1.2)
pg (~> 1.1)
puma (>= 5.0)
rails (~> 7.2.1, >= 7.2.1.1)
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: "[email protected]"
default from: DEFAULT_FROM_EMAIL
layout "mailer"
end
9 changes: 9 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class UserMailer < ApplicationMailer
def welcome_email(user)
@user = user
mail(
to: @user.email,
from: DEFAULT_FROM_EMAIL,
subject: "Welcome to DuelTasks!")
end
end
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class User < ApplicationRecord
after_create :send_welcome_email

has_many :notes, dependent: :destroy
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
Expand All @@ -10,4 +12,10 @@ class User < ApplicationRecord
def subscribed?
subscriptions.where(status: "active").any?
end

private

def send_welcome_email
UserMailer.welcome_email(self).deliver_now
end
end
4 changes: 4 additions & 0 deletions app/views/user_mailer/welcome_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1>Welcome to DuelTasks, <%= @user.email %>!</h1>
<p>
Thanks for signing up! We're excited to have you on board.
</p>
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
G5dDwefYLHBRveb+GZvy6vn+tq1vrScBN+wPoG8umciK4GKOFDvuJQ4UR1Rq5kvgb8pQrK6K/lAFZKNsu0j7EWCBjca5xmjN4XUzXtdIqd9C7Lox9Bpmb5rQJChKaeHtkjEsBDRa+EU2XQtnhKo7kZczy0XtSK1PB0P3rOFi95OTdoTsoXvIo4TIhMFTXyCsJUdl1Ezmghlb1WEc5dL7NxShLd1x6JEoxLMqXKizdiFgKmn+eptKD/R5c9xCfU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qeq7OXsAEC50Txjd6fZQNzve7PWiKCphNcc73gvP3jd8yYXxfHlUtzjWoUBWw24Esa4phVpuYI3UXCAgM5f87jyLtpodr5I1e5qqIB8F3OucA+v4WysYHWnRnvXN24LfmBYpTY1oex0Db+nBVme0Gjay9zPK0U6SWLmKrN7nCqqUBLFmO/hKBbwELj8me1q1HSeuhP6L+Y+63DdfPcJYpCEdHbiwKi13LVSYMfKUsordmkd27k2k0fyHnXN1lU7mBRM1l8CLrWst6dACV/XFXPpc30qpi6LhuDAN1BoikLdHPZhz0IVRZFsjfvSWOd6VijSYyTz01G+BZYcOp6q35z2PxYzFn8h4P84VPisfQb5QCBxS2I+vyc61tlGwjjNuJfP2Jqp3r50Zn6soA79tYv+nDclCRRjm0Hnnc4LdGxnPmPDHdLK1qTg0MdLS/jImLeovHvt0euA9uSxQdB1bstnar2hQlLIq6+cMEv+XCau39mQD5cowFJVg==--sYV6yPnRB8ok1Ejj--ITcyDsuUZ/nyOfKPdh3KsA==
2 changes: 1 addition & 1 deletion config/credentials/production.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
q0xKKh9IEQyYexeiw2rXEPoskS8yol/EoNuCSkkqqS07gDY4a2S1B1iz4jrSQ1ZdJ1WgHXayNJ8TnaXM3gv87WFkzuPOIVJynHh+Ul0+lnfcJw3q9IfsdGohdNMQaRVtPX1JtIrtQT2yXJ58xzwOE2nnVOYT0Kfdj37na5JyXEYo0pImLyFP3iCYybDyJETpDGeiq4fBwd6xoGr9ubk/CGYnl7xaUUyqxOAq3GmJp+gT/+b/dAmgdoTFtaDMHUSxQrIKkUC9LOaM1VyXVy9Ky81HMp9uYDUBEZbFR73iCzV9Zo5qUKEBVQ8ZiQPu3UE+k64vcJyKSE7ZYU1NGUpGswkUFmje/Op25SvUhTY22GB4RX1J+GD8keScQgo0h0QsMciXzXw3uZG/McA0XFFW94aVcmdKwZsQTYyIQ5wNjJnsQY0Y3iWlhraW9piCGoSoJlV3yh/5nhmlume61GYA0AN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RLoK6P3I2Wg6p5TAh0wS+EjTTzX8G4wX2hT93r+HK5/TIefNdFGDsceno6RgVEje7ZLtPiaVM+UetXRW3qspuBkOgo93JEqWRbnheGTDcqQUG73PUCw6DIVxIYeHupmu9kCW6HP3LaoBtQtldTKTBdimdNrNjbWmPQyyxzbBTZj+Cv0EoHSY1v8AOkYoJEIk4iG9e0Y6xs4xHwyF9DPVbK+vFzQZpb28U1e0wITbexHQgSmV4j/fSDWj9guUnjfbTXzA2GoSetdoRhV4MvenRN9q+pSTkMdfMU1W8gmV/nKX2G2d8zezbF81PoS2xqmVoxX6X3oXOuoKCMhikniRv+EDCppte/27ueu8VX3UQd/DRBd/u+UrpcAx+3330JWuFJVMJ0rsF7duwoY4bgxTvhCuDunVL4fnrBQMMR0U26iQZ2/J1cZrFmuQCDRIfR61wVEJT1LOzmp0ImJM3S99EMDmCvfWrusvKSbpEqUN6AYDJEoDw7YosaA5Y5q1rkrXuYO960fHRxNC5KpxIho/tqaf5j3jJ+WRK6tOM61DZSjXEj8sPnBHZZVnro54NtkPB3BzRMnByY+VzkAaS51TTfX0YuKwxoWlnzcOfHPSjoQaMxYpvkhUUj5n+Jvfz1CJgMaw4BpWmJlUtpumVa0SlSozopF9F/4EiQc/fZMHGpAmVHwhPXD2ANbmpLhhMCd2prkml9BjeYSDPBM2/7Q6z8aE7JZfy4ROZX8JPtxFxPbhSIk0z3JXHm2VelySAtC/Uk6kMKmjySykOXAFc4oHopTL/fX2e/cGTNtarTFXC0tMlu4F9K4zSKFLeaFhdb1V4R7uuyqArbZMrdQ+WOm25HqbV57D34G6KOP6Bpb2SuErv3CCWGEz34y/KmFD--lgeBOXePsfgCbGJB--5varNjO6D2E0wzdiKyWLNg==
7 changes: 7 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@

config.action_mailer.default_url_options = { host: "localhost", port: 3000 }

# Mailgun configuration
config.action_mailer.delivery_method = :mailgun
config.action_mailer.mailgun_settings = {
api_key: Rails.application.credentials.dig(:mailgun, :api_key),
domain: Rails.application.credentials.dig(:mailgun, :domain)
}

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

Expand Down
7 changes: 7 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false

# Mailgun configuration
config.action_mailer.delivery_method = :mailgun
config.action_mailer.mailgun_settings = {
api_key: Rails.application.credentials.dig(:mailgun, :api_key),
domain: Rails.application.credentials.dig(:mailgun, :domain)
}

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/constants.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
APP_NAME = "DuelTasks"
GITHUB_LINK = "https://github.com/adnjoo/dueltasks"
X_LINK = "https://x.com/dueltasks"
DOMAIN = "dueltasks.com"
DEFAULT_FROM_EMAIL = "[email protected]"

# Subscription Prices
SUBSCRIPTION_PRICE_MONTHLY = 1
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class
# with default "from" parameter.
config.mailer_sender = "[email protected]"
config.mailer_sender = "no-reply@#{DOMAIN}"

# Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer'
Expand Down
3 changes: 3 additions & 0 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 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

0 comments on commit 39e87ca

Please sign in to comment.