Create Action Mailbox Sample Application

Create Action Mailbox Sample Application

Ecf4ad5c20312b8499a615263519290a?s=128

horikawa

June 25, 2019
Tweet

Transcript

  1. Rails 6.0ͷ
 Action Mailbox ݕূ
 (megurorb#28) גࣜձࣾπΫϧόɹαʔόαΠυΤϯδχΞ ງ઒ɹ@CASIXx1

  2. • ීஈ͸ʮcowcamoʯͱ͍͏ΞϓϦΛ։ൃͯ͠ ·͢ • αʔόαΠυ͸ɺRailsʢ5.2ʣΛ࢖ͬͯ·͢

  3. Rails 6.0.0͕ͦΖͦΖग़ͦ͏ʂ

  4. Rails 6.0.0.rc1͕ग़͍ͯΔͷ Ͱɺ΄΅6.0ͷػೳ͸ࢼͤΔʂ

  5. ৭ʑ௥Ճ͞Ε͍ͯΔ

  6. Rails 6.0ͷओཁ௥Ճػೳ • Action Text • Action Mailbox • Multiple

    Databases • Parallel Testing • Zeitwerk...etc
  7. Action Textͷ࿩୊͸
 ฉ͚͘Ͳɺɺ

  8. Action Mailboxͷ࿩͸ฉ͔ͳ͍...
 
 Qiita΍ϒϩά΋΄΅ͳ͍!

  9. Action MailboxͰ
 αϯϓϧ࡞ͬͯΈ·ͨ͠

  10. ݩʑɺผͷgemͱ࣮ͯ͠૷͞Ε ͍ͯͨ

  11. ͪ͜Βͷϒϩά͸ɺ
 gemΛࢼ͍ͯ͠Δ https://bagelee.com/programming/ruby-on-rails/rails6-action-mailbox/

  12. Rails 5.2Ͱ΋࢖͑ͦ͏???

  13. Action Mailbox֓ཁ

  14. Action Mailboxͱ͸ʁ • ड৴ϝʔϧʹରͯ͠ɺʮRailsʯ಺Ͱɺॲཧ͢Δʂ • S3ʹอଘͨ͠Γɺ
 Action MailerΛ࢖ͬͯɺࣗಈฦ৴ͨ͠Γ… • ฦ৴ϝʔϧΛ΢ΣϒʹࡌͤͨΓ

  15. 4FOE(SJE Ϣʔβʔ ϝʔϧૹ৴ RailsʹHTTP Post ɹ3BJMT "DUJPO.BJMCPY ॲཧ %# อଘ

    4
  16. ಋೖํ๏

  17. ॳظઃఆ • $ rails action_mailbox:install • ApplicationMailboxΫϥε͕ੜ੒͞ΕΔ • MailboxΛ֨ೲ͢Δςʔϒϧ͕ੜ੒͞ΕΔ •

    ActiveStorage΋ಉ࣌ʹΠϯετʔϧ͞ΕΔ
  18. ༨ஊ • ActiveStorageͷMigration Version͸ 5.2Ͱ
 ੜ੒͞ΕΔ͕ɺਖ਼͍͠໛༷ • https://github.com/rails/rails/pull/32042

  19. app/mailboxes/application_mailbox.rb class ApplicationMailbox < ActionMailbox::Base # meguro@hoge.comѼͷϝʔϧ͸ # MegurosMailboxΫϥε಺ͰɺॲཧΛߦ͏ routing

    /^meguro@/i => :meguros end
  20. ϝʔϧ͸ɺ
 ActionMailbox::InboundEmail
 Ϟσϧͱͯ͠ѻΘΕΔ • class InboundEmail < ActiveRecord::Base • https://github.com/rails/rails/blob/

    master/actionmailbox/app/models/ action_mailbox/inbound_email.rb • ActiveStorageͱࣅͨΑ͏ͳײ͡??
  21. app/mailboxes/application_mailbox.rb • ஫ҙ • routingʹରԠ͢ΔϝʔϧΞυϨεʹૹΔͱɺ
 ϝʔϧ͕delivered ѻ͍ • ରԠ͠ͳ͍ϝʔϧΞυϨεʹૹΔͱɺ
 bounced

    ѻ͍ʹͳΔ • ྫʣ #<ActionMailbox::InboundEmail id: ..., status: "bounced", ...>]>
  22. None
  23. ϝʔϧαʔϏεड͚ೖΕઃఆ • 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Λαϙʔτ͍ͯ͠Δ
  24. ύεϫʔυઃఆ • SendGridͳͲͷϝʔϧαʔϏεͱͷ࿈ܞͰɺ ύεϫʔυ͕ٻΊΒΕΔͷͰɺ
 
 ؀ڥม਺ or CredentialsͰύεϫʔυΛ
 RailsଆͰઃఆ͓ͯ͘͠
 


    ྫʣCredentials
  25. ϝʔϧαʔϏεଆͷઃఆ ྫɿSendGrid SendGrid͔ΒɺHTTP POSTͯ͠΋Β͏ʂ https://actionmailbox:password@domain/rails/ action_mailbox/sendgrid/inbound_emails

  26. Sender Authenticationͷઃఆ๨Εͣʹ ϝʔϧΛड৴͢ΔυϝΠϯʹରͯ͠ɺ
 DNSઃఆΛͯ͠Լ͍͞
 
 Status͕ Verifiedʹͳ͍ͬͯͨΒɺOK

  27. S3ͷઃఆ • Active StorageͱS3Λܨ͛Δ͚ͩͰ
 Action Mailboxͱউखʹ࿈ܞͯ͘͠Ε·͢ • ↓͜Μͳσʔλ͕ೖΓ·͢

  28. σϞ

  29. ϝʔϧΛ
 meguro@beif.jpʹૹΔͱɺ಺༰͕ˣʹࡌΓ·͢
 
 https://www.beif.jp/mailbox/megurorbs
 
 ʢ͜ͷαΠτ͸͙͢Ϋϩʔζ͢Δ༧ఆʣ

  30. ิ଍

  31. S3͔ΒϝʔϧϑΝΠϧΛμ΢ϯϩʔυ͢Δ͜ͱͰ Mail::MessageͷϝιουΛ࢖͑Δ

  32. 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
  33. ૹ৴ݩΞυϨεͳͲ΋औΕΔ

  34. ૹ৴ݩΞυϨεͳͲ΋औΕΔ

  35. ·ͱΊ

  36. ·ͱΊ • ϝʔϧαʔϏεଆͷઃఆ΋ඞཁʹͳΔ • SendGridͳΒɺInbound ParseͳͲ • SES͸ɺRails 6.1͔ΒͷαϙʔτͱͳΓͦ͏ •

    https://github.com/rails/rails/commit/ f480cfabcd9000b5817b610e21466299025b12d2 • ࣍ճ͸ • ࣗಈฦ৴ͱ͔
 Ϣʔβʔςʔϒϧͱૹ৴͞ΕͨϝʔϧͷΞυϨεΛಥ͖߹Θͤͯɺ
 ͲͷϢʔβʔ͕ϝʔϧΛૹͬͨͷ͔Λ෼͔ΔΑ͏ʹͯ͠ΈΔ • InboundEmail͔Βͷ৘ใऔಘΛͲΕ͚ͩ޻෉Ͱ͖Δ͔
  37. ऴΘΓ

  38. ࢀߟ • 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/