Skip to content

Commit cc125c6

Browse files
authored
example: return email id from smtp response (#21)
1 parent c35d124 commit cc125c6

File tree

6 files changed

+91
-111
lines changed

6 files changed

+91
-111
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
44
ruby ">3.0"
55

66
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
7-
gem "rails", "~> 7.1.0"
7+
gem "rails", "~> 7.0.0"
88

99
# Use sqlite3 as the database for Active Record
1010
gem "sqlite3", "~> 1.4"

Gemfile.lock

+80-103
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,85 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
actioncable (7.1.3.2)
5-
actionpack (= 7.1.3.2)
6-
activesupport (= 7.1.3.2)
4+
actioncable (7.0.4)
5+
actionpack (= 7.0.4)
6+
activesupport (= 7.0.4)
77
nio4r (~> 2.0)
88
websocket-driver (>= 0.6.1)
9-
zeitwerk (~> 2.6)
10-
actionmailbox (7.1.3.2)
11-
actionpack (= 7.1.3.2)
12-
activejob (= 7.1.3.2)
13-
activerecord (= 7.1.3.2)
14-
activestorage (= 7.1.3.2)
15-
activesupport (= 7.1.3.2)
9+
actionmailbox (7.0.4)
10+
actionpack (= 7.0.4)
11+
activejob (= 7.0.4)
12+
activerecord (= 7.0.4)
13+
activestorage (= 7.0.4)
14+
activesupport (= 7.0.4)
1615
mail (>= 2.7.1)
1716
net-imap
1817
net-pop
1918
net-smtp
20-
actionmailer (7.1.3.2)
21-
actionpack (= 7.1.3.2)
22-
actionview (= 7.1.3.2)
23-
activejob (= 7.1.3.2)
24-
activesupport (= 7.1.3.2)
19+
actionmailer (7.0.4)
20+
actionpack (= 7.0.4)
21+
actionview (= 7.0.4)
22+
activejob (= 7.0.4)
23+
activesupport (= 7.0.4)
2524
mail (~> 2.5, >= 2.5.4)
2625
net-imap
2726
net-pop
2827
net-smtp
29-
rails-dom-testing (~> 2.2)
30-
actionpack (7.1.3.2)
31-
actionview (= 7.1.3.2)
32-
activesupport (= 7.1.3.2)
33-
nokogiri (>= 1.8.5)
34-
racc
35-
rack (>= 2.2.4)
36-
rack-session (>= 1.0.1)
28+
rails-dom-testing (~> 2.0)
29+
actionpack (7.0.4)
30+
actionview (= 7.0.4)
31+
activesupport (= 7.0.4)
32+
rack (~> 2.0, >= 2.2.0)
3733
rack-test (>= 0.6.3)
38-
rails-dom-testing (~> 2.2)
39-
rails-html-sanitizer (~> 1.6)
40-
actiontext (7.1.3.2)
41-
actionpack (= 7.1.3.2)
42-
activerecord (= 7.1.3.2)
43-
activestorage (= 7.1.3.2)
44-
activesupport (= 7.1.3.2)
34+
rails-dom-testing (~> 2.0)
35+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
36+
actiontext (7.0.4)
37+
actionpack (= 7.0.4)
38+
activerecord (= 7.0.4)
39+
activestorage (= 7.0.4)
40+
activesupport (= 7.0.4)
4541
globalid (>= 0.6.0)
4642
nokogiri (>= 1.8.5)
47-
actionview (7.1.3.2)
48-
activesupport (= 7.1.3.2)
43+
actionview (7.0.4)
44+
activesupport (= 7.0.4)
4945
builder (~> 3.1)
50-
erubi (~> 1.11)
51-
rails-dom-testing (~> 2.2)
52-
rails-html-sanitizer (~> 1.6)
53-
activejob (7.1.3.2)
54-
activesupport (= 7.1.3.2)
46+
erubi (~> 1.4)
47+
rails-dom-testing (~> 2.0)
48+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
49+
activejob (7.0.4)
50+
activesupport (= 7.0.4)
5551
globalid (>= 0.3.6)
56-
activemodel (7.1.3.2)
57-
activesupport (= 7.1.3.2)
58-
activerecord (7.1.3.2)
59-
activemodel (= 7.1.3.2)
60-
activesupport (= 7.1.3.2)
61-
timeout (>= 0.4.0)
62-
activestorage (7.1.3.2)
63-
actionpack (= 7.1.3.2)
64-
activejob (= 7.1.3.2)
65-
activerecord (= 7.1.3.2)
66-
activesupport (= 7.1.3.2)
52+
activemodel (7.0.4)
53+
activesupport (= 7.0.4)
54+
activerecord (7.0.4)
55+
activemodel (= 7.0.4)
56+
activesupport (= 7.0.4)
57+
activestorage (7.0.4)
58+
actionpack (= 7.0.4)
59+
activejob (= 7.0.4)
60+
activerecord (= 7.0.4)
61+
activesupport (= 7.0.4)
6762
marcel (~> 1.0)
68-
activesupport (7.1.3.2)
69-
base64
70-
bigdecimal
63+
mini_mime (>= 1.1.0)
64+
activesupport (7.0.4)
7165
concurrent-ruby (~> 1.0, >= 1.0.2)
72-
connection_pool (>= 2.2.5)
73-
drb
7466
i18n (>= 1.6, < 2)
7567
minitest (>= 5.1)
76-
mutex_m
7768
tzinfo (~> 2.0)
78-
base64 (0.2.0)
79-
bigdecimal (1.4.4)
8069
bootsnap (1.18.3)
8170
msgpack (~> 1.2)
82-
builder (3.2.4)
71+
builder (3.3.0)
8372
coderay (1.1.3)
84-
concurrent-ruby (1.2.3)
85-
connection_pool (2.4.1)
73+
concurrent-ruby (1.3.3)
8674
crass (1.0.6)
8775
date (3.3.4)
8876
debug (1.9.1)
8977
irb (~> 1.10)
9078
reline (>= 0.3.8)
91-
drb (2.2.0)
92-
ruby2_keywords
93-
erubi (1.12.0)
79+
erubi (1.13.0)
9480
globalid (1.2.1)
9581
activesupport (>= 6.1)
96-
i18n (1.14.1)
82+
i18n (1.14.5)
9783
concurrent-ruby (~> 1.0)
9884
io-console (0.7.2)
9985
irb (1.11.2)
@@ -107,25 +93,22 @@ GEM
10793
net-imap
10894
net-pop
10995
net-smtp
110-
marcel (1.0.2)
96+
marcel (1.0.4)
11197
method_source (1.0.0)
11298
mini_mime (1.1.5)
113-
minitest (5.22.2)
99+
minitest (5.23.1)
114100
msgpack (1.7.2)
115-
mutex_m (0.2.0)
116-
net-imap (0.4.10)
101+
net-imap (0.4.12)
117102
date
118103
net-protocol
119104
net-pop (0.1.2)
120105
net-protocol
121106
net-protocol (0.2.2)
122107
timeout
123-
net-smtp (0.4.0.1)
108+
net-smtp (0.5.0)
124109
net-protocol
125110
nio4r (2.7.0)
126-
nokogiri (1.16.2-x86_64-darwin)
127-
racc (~> 1.4)
128-
nokogiri (1.16.2-x86_64-linux)
111+
nokogiri (1.16.6-arm64-darwin)
129112
racc (~> 1.4)
130113
pry (0.14.2)
131114
coderay (~> 1.1)
@@ -134,64 +117,58 @@ GEM
134117
stringio
135118
puma (6.4.2)
136119
nio4r (~> 2.0)
137-
racc (1.7.3)
120+
racc (1.8.0)
138121
rack (2.2.8.1)
139-
rack-session (1.0.2)
140-
rack (< 3)
141122
rack-test (2.1.0)
142123
rack (>= 1.3)
143-
rackup (1.0.0)
144-
rack (< 3)
145-
webrick
146-
rails (7.1.3.2)
147-
actioncable (= 7.1.3.2)
148-
actionmailbox (= 7.1.3.2)
149-
actionmailer (= 7.1.3.2)
150-
actionpack (= 7.1.3.2)
151-
actiontext (= 7.1.3.2)
152-
actionview (= 7.1.3.2)
153-
activejob (= 7.1.3.2)
154-
activemodel (= 7.1.3.2)
155-
activerecord (= 7.1.3.2)
156-
activestorage (= 7.1.3.2)
157-
activesupport (= 7.1.3.2)
124+
rails (7.0.4)
125+
actioncable (= 7.0.4)
126+
actionmailbox (= 7.0.4)
127+
actionmailer (= 7.0.4)
128+
actionpack (= 7.0.4)
129+
actiontext (= 7.0.4)
130+
actionview (= 7.0.4)
131+
activejob (= 7.0.4)
132+
activemodel (= 7.0.4)
133+
activerecord (= 7.0.4)
134+
activestorage (= 7.0.4)
135+
activesupport (= 7.0.4)
158136
bundler (>= 1.15.0)
159-
railties (= 7.1.3.2)
137+
railties (= 7.0.4)
160138
rails-dom-testing (2.2.0)
161139
activesupport (>= 5.0.0)
162140
minitest
163141
nokogiri (>= 1.6)
164142
rails-html-sanitizer (1.6.0)
165143
loofah (~> 2.21)
166144
nokogiri (~> 1.14)
167-
railties (7.1.3.2)
168-
actionpack (= 7.1.3.2)
169-
activesupport (= 7.1.3.2)
170-
irb
171-
rackup (>= 1.0.0)
145+
railties (7.0.4)
146+
actionpack (= 7.0.4)
147+
activesupport (= 7.0.4)
148+
method_source
172149
rake (>= 12.2)
173-
thor (~> 1.0, >= 1.2.2)
174-
zeitwerk (~> 2.6)
175-
rake (13.1.0)
150+
thor (~> 1.0)
151+
zeitwerk (~> 2.5)
152+
rake (13.2.1)
176153
rdoc (6.6.2)
177154
psych (>= 4.0.0)
178155
reline (0.4.2)
179156
io-console (~> 0.5)
180-
ruby2_keywords (0.0.5)
157+
sqlite3 (1.6.2-arm64-darwin)
181158
sqlite3 (1.6.2-x86_64-darwin)
182159
sqlite3 (1.6.2-x86_64-linux)
183160
stringio (3.1.0)
184-
thor (1.3.0)
161+
thor (1.3.1)
185162
timeout (0.4.1)
186163
tzinfo (2.0.6)
187164
concurrent-ruby (~> 1.0)
188-
webrick (1.8.1)
189165
websocket-driver (0.7.6)
190166
websocket-extensions (>= 0.1.0)
191167
websocket-extensions (0.1.5)
192-
zeitwerk (2.6.13)
168+
zeitwerk (2.6.15)
193169

194170
PLATFORMS
171+
arm64-darwin-22
195172
x86_64-darwin-20
196173
x86_64-darwin-21
197174
x86_64-linux
@@ -201,7 +178,7 @@ DEPENDENCIES
201178
debug
202179
pry
203180
puma (~> 6.0)
204-
rails (~> 7.1.0)
181+
rails (~> 7.0.0)
205182
sqlite3 (~> 1.4)
206183
tzinfo-data
207184

app/controllers/user_controller.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ class UserController < ApplicationController
33
def send_hello_email
44
@user = User.new(name: "derich")
55

6-
r = UserMailer.with(user: @user).welcome_email.deliver!
7-
render json: {status: 'ok'}
6+
# Make sure return_response is set to true in the SMTP smtp_settings object
7+
# so that we get an Net::SMTP::Response object here.
8+
smtp_response = UserMailer.with(user: @user).welcome_email.deliver!
9+
render json: {
10+
email_id: smtp_response.message.split(" ")[1].strip
11+
}
812
end
913

1014
def healthz

app/mailers/application_mailer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class ApplicationMailer < ActionMailer::Base
2-
default from: "[email protected]"
2+
default from: "[email protected]"
33
layout "mailer"
44
end

app/mailers/user_mailer.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
class UserMailer < ApplicationMailer
22
# this domain must be verified with Resend
3-
default from: "[email protected]"
3+
default from: "[email protected]"
44

55
def welcome_email
66
@user = params[:user]
77
attachments["invoice.pdf"] = File.read(Rails.root.join("resources","invoice.pdf"))
88
@url = "http://example.com/login"
99
mail(
10-
11-
12-
10+
1311
reply_to: "[email protected]",
1412
subject: "Hello from Rails",
1513
)

config/environments/development.rb

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
:port => 465,
6161
:user_name => 'resend',
6262
:password => ENV['RESEND_API_KEY'],
63+
:return_response => true,
6364
:tls => true
6465
}
6566
# Raises error for missing translations.

0 commit comments

Comments
 (0)