Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Create Action Mailbox Sample Application
Search
horikawa
June 25, 2019
Technology
450
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Create Action Mailbox Sample Application
horikawa
June 25, 2019
More Decks by horikawa
See All by horikawa
Caching associations in rails
casix
1
330
Rails 4.2→5.2アップデート
casix
0
460
Rails 6.0 Action Mailboxについて
casix
0
400
Other Decks in Technology
See All in Technology
AIエージェントを前提としたプラットフォーム エンジニアリング:GKEで作るAgent-Ready Golden Path
legalontechnologies
PRO
1
130
PLaMo 3.0 Primeの構造化出力サポート
pfn
PRO
0
180
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
53k
Service Connect 上のサービスに ECS Service の外側から到達できなかった話
ota1022
1
110
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
19k
【CEDEC2026】専門性の高いデフォルメチームが挑んだ人材育成戦略 〜Cygames Academiaの企画から実施まで〜
cygames
PRO
0
130
AIが自社のTableauを操作する世界へ:Tableau MCP超入門
tbtykk
0
110
今こそ聞きたいソフトウェア設計 ドメイン駆動設計再入門
masuda220
PRO
12
4.3k
Eight Engineering Unit 紹介資料
sansan33
PRO
3
8.1k
Forza Horizon 6 のテレメトリ機能で 自動運転に使えそうな学習データを集める話
henjin0
0
120
個人OSSが、机の上から世界に広がるまでの話
shinyasaita
1
340
データエンジニアこそ組織のオントロジーに向き合うべき — 問いに答えるAIから、事業を動かすAIへ
gappy50
7
3.2k
Featured
See All Featured
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
630
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
How to train your dragon (web standard)
notwaldorf
97
6.7k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
270
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.2k
4 Signs Your Business is Dying
shpigford
187
22k
30 Presentation Tips
portentint
PRO
1
360
My Coaching Mixtape
mlcsv
0
190
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.7k
Transcript
Rails 6.0ͷ Action Mailbox ݕূ (megurorb#28) גࣜձࣾπΫϧόɹαʔόαΠυΤϯδχΞ ງɹ@CASIXx1
• ීஈʮcowcamoʯͱ͍͏ΞϓϦΛ։ൃͯ͠ ·͢ • αʔόαΠυɺRailsʢ5.2ʣΛͬͯ·͢
Rails 6.0.0͕ͦΖͦΖग़ͦ͏ʂ
Rails 6.0.0.rc1͕ग़͍ͯΔͷ Ͱɺ΄΅6.0ͷػೳࢼͤΔʂ
৭ʑՃ͞Ε͍ͯΔ
Rails 6.0ͷओཁՃػೳ • Action Text • Action Mailbox • Multiple
Databases • Parallel Testing • Zeitwerk...etc
Action Textͷ ฉ͚͘Ͳɺɺ
Action Mailboxͷฉ͔ͳ͍... Qiitaϒϩά΄΅ͳ͍!
Action MailboxͰ αϯϓϧ࡞ͬͯΈ·ͨ͠
ݩʑɺผͷgemͱ࣮ͯ͠͞Ε ͍ͯͨ
ͪ͜Βͷϒϩάɺ gemΛࢼ͍ͯ͠Δ https://bagelee.com/programming/ruby-on-rails/rails6-action-mailbox/
Rails 5.2Ͱ͑ͦ͏???
Action Mailbox֓ཁ
Action Mailboxͱʁ • ड৴ϝʔϧʹରͯ͠ɺʮRailsʯͰɺॲཧ͢Δʂ • S3ʹอଘͨ͠Γɺ Action MailerΛͬͯɺࣗಈฦ৴ͨ͠Γ… • ฦ৴ϝʔϧΛΣϒʹࡌͤͨΓ
4FOE(SJE Ϣʔβʔ ϝʔϧૹ৴ RailsʹHTTP Post ɹ3BJMT "DUJPO.BJMCPY ॲཧ %# อଘ
4
ಋೖํ๏
ॳظઃఆ • $ rails action_mailbox:install • ApplicationMailboxΫϥε͕ੜ͞ΕΔ • MailboxΛ֨ೲ͢Δςʔϒϧ͕ੜ͞ΕΔ •
ActiveStorageಉ࣌ʹΠϯετʔϧ͞ΕΔ
༨ஊ • ActiveStorageͷMigration Version 5.2Ͱ ੜ͞ΕΔ͕ɺਖ਼͍༷͠ • https://github.com/rails/rails/pull/32042
app/mailboxes/application_mailbox.rb class ApplicationMailbox < ActionMailbox::Base #
[email protected]
Ѽͷϝʔϧ # MegurosMailboxΫϥεͰɺॲཧΛߦ͏ routing
/^meguro@/i => :meguros end
ϝʔϧɺ ActionMailbox::InboundEmail Ϟσϧͱͯ͠ѻΘΕΔ • class InboundEmail < ActiveRecord::Base • https://github.com/rails/rails/blob/
master/actionmailbox/app/models/ action_mailbox/inbound_email.rb • ActiveStorageͱࣅͨΑ͏ͳײ͡??
app/mailboxes/application_mailbox.rb • ҙ • routingʹରԠ͢ΔϝʔϧΞυϨεʹૹΔͱɺ ϝʔϧ͕delivered ѻ͍ • ରԠ͠ͳ͍ϝʔϧΞυϨεʹૹΔͱɺ bounced
ѻ͍ʹͳΔ • ྫʣ #<ActionMailbox::InboundEmail id: ..., status: "bounced", ...>]>
None
ϝʔϧαʔϏεड͚ೖΕઃఆ • config/environments/֤ڥ.rb config.action_mailbox.ingress = # ͜͜ʹαʔϏε໊ # sendgridͷ߹ config.action_mailbox.ingress
= :sendgrid # mailgunͷ߹ config.action_mailbox.ingress = :mailgun # exam, mailgun, mandrill, postfix, postmark, qmail, sendgridΛαϙʔτ͍ͯ͠Δ
ύεϫʔυઃఆ • SendGridͳͲͷϝʔϧαʔϏεͱͷ࿈ܞͰɺ ύεϫʔυ͕ٻΊΒΕΔͷͰɺ ڥม or CredentialsͰύεϫʔυΛ RailsଆͰઃఆ͓ͯ͘͠
ྫʣCredentials
ϝʔϧαʔϏεଆͷઃఆ ྫɿSendGrid SendGrid͔ΒɺHTTP POSTͯ͠Β͏ʂ https://actionmailbox:password@domain/rails/ action_mailbox/sendgrid/inbound_emails
Sender AuthenticationͷઃఆΕͣʹ ϝʔϧΛड৴͢ΔυϝΠϯʹରͯ͠ɺ DNSઃఆΛͯ͠Լ͍͞ Status͕ Verifiedʹͳ͍ͬͯͨΒɺOK
S3ͷઃఆ • Active StorageͱS3Λܨ͛Δ͚ͩͰ Action Mailboxͱউखʹ࿈ܞͯ͘͠Ε·͢ • ↓͜Μͳσʔλ͕ೖΓ·͢
σϞ
ϝʔϧΛ
[email protected]
ʹૹΔͱɺ༰͕ˣʹࡌΓ·͢ https://www.beif.jp/mailbox/megurorbs ʢ͜ͷαΠτ͙͢Ϋϩʔζ͢Δ༧ఆʣ
ิ
S3͔ΒϝʔϧϑΝΠϧΛμϯϩʔυ͢Δ͜ͱͰ Mail::MessageͷϝιουΛ͑Δ
S3͔ΒϝʔϧϑΝΠϧΛμϯϩʔυ͢Δ͜ͱͰ Mail::MessageͷϝιουΛ͑Δ • > ActionMailbox::InboundEmail.first.mail.class • D, [2019-06-25T00:41:49.319609 #4] DEBUG
-- : ActionMailbox::InboundEmail Load (1.5ms) SELECT "action_mailbox_inbound_emails".* FROM "action_mailbox_inbound_emails" ORDER BY "action_mailbox_inbound_emails"."id" ASC LIMIT $1 [["LIMIT", 1]] • D, [2019-06-25T00:41:49.348480 #4] DEBUG -- : ActiveStorage::Attachment Load (2.6ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4 [["record_id", 9], ["record_type", "ActionMailbox::InboundEmail"], ["name", "raw_email"], ["LIMIT", 1]] • D, [2019-06-25T00:41:49.351096 #4] DEBUG -- : ActiveStorage::Blob Load (1.5ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2 [["id", 9], ["LIMIT", 1]] • I, [2019-06-25T00:41:50.006908 #4] INFO -- : S3 Storage (655.4ms) Downloaded file from key: hogehogehogehogehoge • => Mail::Message
ૹ৴ݩΞυϨεͳͲऔΕΔ
ૹ৴ݩΞυϨεͳͲऔΕΔ
·ͱΊ
·ͱΊ • ϝʔϧαʔϏεଆͷઃఆඞཁʹͳΔ • SendGridͳΒɺInbound ParseͳͲ • SESɺRails 6.1͔ΒͷαϙʔτͱͳΓͦ͏ •
https://github.com/rails/rails/commit/ f480cfabcd9000b5817b610e21466299025b12d2 • ࣍ճ • ࣗಈฦ৴ͱ͔ Ϣʔβʔςʔϒϧͱૹ৴͞ΕͨϝʔϧͷΞυϨεΛಥ͖߹Θͤͯɺ ͲͷϢʔβʔ͕ϝʔϧΛૹͬͨͷ͔Λ͔ΔΑ͏ʹͯ͠ΈΔ • InboundEmail͔ΒͷใऔಘΛͲΕ͚ͩͰ͖Δ͔
ऴΘΓ
ࢀߟ • Action Mailbox gem • https://github.com/rails/actionmailbox/tree/master • Rails Guides
• https://edgeguides.rubyonrails.org/ action_mailbox_basics.html • bagelee • https://bagelee.com/programming/ruby-on-rails/rails6- action-mailbox/