Rails 6.0 Action Mailboxについて

Rails 6.0 Action Mailboxについて

otemachi.rb#17で発表した資料

Ecf4ad5c20312b8499a615263519290a?s=128

horikawa

May 15, 2019
Tweet

Transcript

  1. Rails 6.0ͷ
 Action Mailbox גࣜձࣾπΫϧόɹαʔόαΠυΤϯδχΞ ງ઒ɹ@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ͷ࿩͸ฉ͔ͳ͍...

  9. Action Mailboxͷ͜ͱΛ
 ௐ΂ͯΈ·ͨ͠ 
 ʢ·్ͩத·Ͱ͔͠
 ࢼͤͯ͸ͳ͍ ʣ

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

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

  12. Action Mailboxͷػೳ • ड৴ϝʔϧʹରͯ͠ɺʮRailsʯ಺Ͱɺॲཧ͢Δʂ • DB΍S3ʹอଘͨ͠ΓɺAction MailerΛ࢖ͬͯɺ ࣗಈฦ৴ͨ͠Γ…

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

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

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

    /^save@/i => :forwards 
 # hoge@replies.comѼͷϝʔϧ͸ # RepliesMailboxΫϥε಺ͰɺॲཧΛߦ͏ routing /@replies\./i => :replies end
  16. ϝʔϧ͸ɺInboundEmailϞσ ϧͱͯ͠ѻΘΕΔ • class InboundEmail < ActiveRecord::Base • https://github.com/rails/rails/blob/ master/actionmailbox/app/models/

    action_mailbox/inbound_email.rb • ActiveStorageͱࣅͨΑ͏ͳײ͡??
  17. SMTPड͚ೖΕઃఆ • 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Λαϙʔτ͍ͯ͠Δ
  18. ύεϫʔυઃఆ • SendGridͳͲͷϝʔϧαʔϏεͱͷ࿈ܞͰɺ ύεϫʔυ͕ٻΊΒΕΔͷͰɺ
 
 ؀ڥม਺ or CredentialͰύεϫʔυΛ
 RailsଆͰઃఆ͓ͯ͘͠

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

  20. ศརͳҹ৅ • RspecͳͲͰͷςετ΋ॻ͚Δ • ActiveStorageΛ࢖͑͹ɺS3ͳͲʹอଘͰ͖ΔΒ͠ ͍ • Callback΋ग़དྷͦ͏ • https://github.com/rails/rails/blob/master/

    actionmailbox/lib/action_mailbox/callbacks.rb
  21. ؾʹͳͬͨՕॴ • ϝʔϧαʔϏεଆͷઃఆ΋ඞཁʹͳΔ • SendGridͳΒɺInbound ParseͳͲ • Parseͷ࢓༷΋ཧղ͓͔ͯ͠ͳ͍ͱ͍͚ͳ͍ • SES͸ɺRails

    6.1͔ΒͷαϙʔτͱͳΓͦ͏ • https://github.com/rails/rails/commit/ f480cfabcd9000b5817b610e21466299025b12d2 • ެࣜඇެࣜͷυΩϡϝϯτ͕ඇৗʹগͳ͍… • ϝʔϧେྔʹདྷͨΒɺαʔόͲ͏ͳΔͷ͔ͳ…
  22. ·ͱΊ

  23. ·ͱΊ • Rails App಺Ͱ࿈ܞ͕ඞཁͳ৔߹͸ɺॏๅͦ͠ ͏ʂ • ֤؅ཧऀʹϝʔϧΛసૹͨ͠Γ • ࿈ܞ͕ཁΒͳ͍৔߹͸ɺAction Mailbox୯ମ

    ͰαʔόཱͯΕ͹ྑ͍ؾ΋…
  24. ऴΘΓ

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