From 91d159e4b82c97926d3ac6cea8fe1d6763af4ea3 Mon Sep 17 00:00:00 2001 From: Derich Pacheco Date: Fri, 23 Aug 2024 17:29:38 -0300 Subject: [PATCH] fix: showcase getting email id (#27) --- Gemfile | 4 +- Gemfile.lock | 187 +++++++++++++---------------- app/controllers/user_controller.rb | 7 +- app/mailers/user_mailer.rb | 8 +- 4 files changed, 91 insertions(+), 115 deletions(-) diff --git a/Gemfile b/Gemfile index 877e2b5..0a7bdec 100644 --- a/Gemfile +++ b/Gemfile @@ -4,10 +4,10 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby ">3.0" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem "rails", "~> 7.1.0" +gem "rails", "~> 7.0.0" # Use sqlite3 as the database for Active Record -gem "sqlite3", "~> 2.0" +gem "sqlite3", "~> 1.4" # Use the Puma web server [https://github.com/puma/puma] gem "puma", "~> 5.6" diff --git a/Gemfile.lock b/Gemfile.lock index d79a255..a6a3a70 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,104 +1,90 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.1.3) - actionpack (= 7.1.3) - activesupport (= 7.1.3) + actioncable (7.0.4) + actionpack (= 7.0.4) + activesupport (= 7.0.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - zeitwerk (~> 2.6) - actionmailbox (7.1.3) - actionpack (= 7.1.3) - activejob (= 7.1.3) - activerecord (= 7.1.3) - activestorage (= 7.1.3) - activesupport (= 7.1.3) + actionmailbox (7.0.4) + actionpack (= 7.0.4) + activejob (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.1.3) - actionpack (= 7.1.3) - actionview (= 7.1.3) - activejob (= 7.1.3) - activesupport (= 7.1.3) + actionmailer (7.0.4) + actionpack (= 7.0.4) + actionview (= 7.0.4) + activejob (= 7.0.4) + activesupport (= 7.0.4) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.2) - actionpack (7.1.3) - actionview (= 7.1.3) - activesupport (= 7.1.3) - nokogiri (>= 1.8.5) - racc - rack (>= 2.2.4) - rack-session (>= 1.0.1) + rails-dom-testing (~> 2.0) + actionpack (7.0.4) + actionview (= 7.0.4) + activesupport (= 7.0.4) + rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.2) - rails-html-sanitizer (~> 1.6) - actiontext (7.1.3) - actionpack (= 7.1.3) - activerecord (= 7.1.3) - activestorage (= 7.1.3) - activesupport (= 7.1.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (7.0.4) + actionpack (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.3) - activesupport (= 7.1.3) + actionview (7.0.4) + activesupport (= 7.0.4) builder (~> 3.1) - erubi (~> 1.11) - rails-dom-testing (~> 2.2) - rails-html-sanitizer (~> 1.6) - activejob (7.1.3) - activesupport (= 7.1.3) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (7.0.4) + activesupport (= 7.0.4) globalid (>= 0.3.6) - activemodel (7.1.3) - activesupport (= 7.1.3) - activerecord (7.1.3) - activemodel (= 7.1.3) - activesupport (= 7.1.3) - timeout (>= 0.4.0) - activestorage (7.1.3) - actionpack (= 7.1.3) - activejob (= 7.1.3) - activerecord (= 7.1.3) - activesupport (= 7.1.3) + activemodel (7.0.4) + activesupport (= 7.0.4) + activerecord (7.0.4) + activemodel (= 7.0.4) + activesupport (= 7.0.4) + activestorage (7.0.4) + actionpack (= 7.0.4) + activejob (= 7.0.4) + activerecord (= 7.0.4) + activesupport (= 7.0.4) marcel (~> 1.0) - activesupport (7.1.3) - base64 - bigdecimal + mini_mime (>= 1.1.0) + activesupport (7.0.4) concurrent-ruby (~> 1.0, >= 1.0.2) - connection_pool (>= 2.2.5) - drb i18n (>= 1.6, < 2) minitest (>= 5.1) - mutex_m tzinfo (~> 2.0) - base64 (0.2.0) - bigdecimal (1.4.4) bootsnap (1.18.3) msgpack (~> 1.2) - builder (3.2.4) + builder (3.3.0) coderay (1.1.3) - concurrent-ruby (1.2.3) - connection_pool (2.4.1) + concurrent-ruby (1.3.3) crass (1.0.6) csv (0.1.0) date (3.3.4) debug (1.9.1) irb (~> 1.10) reline (>= 0.3.8) - drb (2.2.0) - ruby2_keywords - erubi (1.12.0) + erubi (1.13.0) globalid (1.2.1) activesupport (>= 6.1) httparty (0.22.0) csv mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) - i18n (1.14.1) + i18n (1.14.5) concurrent-ruby (~> 1.0) io-console (0.7.2) irb (1.11.2) @@ -112,26 +98,23 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) method_source (1.0.0) mini_mime (1.1.5) - minitest (5.22.2) + minitest (5.23.1) msgpack (1.7.2) multi_xml (0.6.0) - mutex_m (0.2.0) - net-imap (0.4.10) + net-imap (0.4.12) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.4.0.1) + net-smtp (0.5.0) net-protocol nio4r (2.7.0) - nokogiri (1.16.2-x86_64-darwin) - racc (~> 1.4) - nokogiri (1.16.2-x86_64-linux) + nokogiri (1.16.6-arm64-darwin) racc (~> 1.4) pry (0.14.2) coderay (~> 1.1) @@ -140,29 +123,24 @@ GEM stringio puma (5.6.8) nio4r (~> 2.0) - racc (1.7.3) + racc (1.8.0) rack (2.2.8) - rack-session (1.0.2) - rack (< 3) rack-test (2.1.0) rack (>= 1.3) - rackup (1.0.0) - rack (< 3) - webrick - rails (7.1.3) - actioncable (= 7.1.3) - actionmailbox (= 7.1.3) - actionmailer (= 7.1.3) - actionpack (= 7.1.3) - actiontext (= 7.1.3) - actionview (= 7.1.3) - activejob (= 7.1.3) - activemodel (= 7.1.3) - activerecord (= 7.1.3) - activestorage (= 7.1.3) - activesupport (= 7.1.3) + rails (7.0.4) + actioncable (= 7.0.4) + actionmailbox (= 7.0.4) + actionmailer (= 7.0.4) + actionpack (= 7.0.4) + actiontext (= 7.0.4) + actionview (= 7.0.4) + activejob (= 7.0.4) + activemodel (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) bundler (>= 1.15.0) - railties (= 7.1.3) + railties (= 7.0.4) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -170,36 +148,33 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.1.3) - actionpack (= 7.1.3) - activesupport (= 7.1.3) - irb - rackup (>= 1.0.0) + railties (7.0.4) + actionpack (= 7.0.4) + activesupport (= 7.0.4) + method_source rake (>= 12.2) - thor (~> 1.0, >= 1.2.2) - zeitwerk (~> 2.6) - rake (13.1.0) + thor (~> 1.0) + zeitwerk (~> 2.5) + rake (13.2.1) rdoc (6.6.2) psych (>= 4.0.0) reline (0.4.2) io-console (~> 0.5) resend (0.13.0) httparty (>= 0.21.0) - ruby2_keywords (0.0.5) - sqlite3 (2.0.0-x86_64-darwin) - sqlite3 (2.0.0-x86_64-linux-gnu) + sqlite3 (1.7.3-arm64-darwin) stringio (3.1.0) - thor (1.3.0) + thor (1.3.1) timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - webrick (1.8.1) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.6.13) + zeitwerk (2.6.15) PLATFORMS + arm64-darwin-22 x86_64-darwin-20 x86_64-linux @@ -208,9 +183,9 @@ DEPENDENCIES debug pry puma (~> 5.6) - rails (~> 7.1.0) + rails (~> 7.0.0) resend - sqlite3 (~> 2.0) + sqlite3 (~> 1.4) tzinfo-data RUBY VERSION diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 5061daf..a798d75 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -3,8 +3,11 @@ class UserController < ApplicationController def send_hello_email @user = User.new(name: "derich") - r = UserMailer.with(user: @user).welcome_email.deliver! - render json: {status: 'ok'} + resp = UserMailer.with(user: @user).welcome_email.deliver! + + render json: { + email_id: resp[:id] + } end def healthz diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index cde1fd5..89b57b5 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,16 +1,14 @@ class UserMailer < ApplicationMailer # this domain must be verified with Resend - default from: "from@example.com" + default from: "onboarding@resend.dev" def welcome_email @user = params[:user] attachments["invoice.pdf"] = File.read(Rails.root.join("resources","invoice.pdf")) @url = "http://example.com/login" mail( - to: ["to@example.com"], - cc: ["cc@example.com"], - bcc: ["bcc@example.com"], - reply_to: "replyto@example.com", + to: ["delivered@resend.dev"], + reply_to: "delivered@resend.dev", subject: "Hello from Rails", ) end