Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
340
Rails 4.2→5.2アップデート
casix
0
460
Rails 6.0 Action Mailboxについて
casix
0
410
Other Decks in Technology
See All in Technology
BedrockとLambdaで作る リアルタイム進行型推理ゲーム
kawametho
0
190
3つのアプローチで目指す チームを強くするAI駆動開発
thkt
0
120
ai_cording_with_k8s_knowledge.pdf
mochizuki875
1
300
AI時代のAPI開発を加速する品質ガードレール / API Quality Guardrails in the AI Era
yokawasa
0
160
IR Today: Theory, Practice, and Agents
dtunkelang
0
350
FinTech 1-2 : Overview of FinTech
ks91
PRO
0
150
自主式軟體工廠
philipz
0
230
生成AIと進める探索的データ分析(2026.10.03 第122回Tokyo.R勉強会)
tatamiya
2
1.4k
ファミコンでPHPを動かす / PHP on the Famicom side b
tomzoh
0
140
継続的なAIコスト最適化
bgpat
1
180
プロダクト価値を、 チームが使える判断軸に変える
vivion
0
130
検証フェーズはAIの回答を判断するための学習機会
toru_kubota
2
510
Featured
See All Featured
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
580
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
Making Projects Easy
brettharned
120
6.8k
Odyssey Design
rkendrick25
PRO
2
860
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
WCS-LA-2024
lcolladotor
0
850
[SF Ruby Conf 2025] Rails X
palkan
3
1.4k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
600
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
460
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
530
Code Review Best Practice
trishagee
74
20k
Optimizing for Happiness
mojombo
378
71k
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/