Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Email in Rails (and/or introduction to "Dark Depths of Email")

sylph01
September 18, 2019

Email in Rails (and/or introduction to "Dark Depths of Email")

presented at Fukuoka.rb 150th anniversary LT

sylph01

September 18, 2019
Tweet

More Decks by sylph01

Other Decks in Technology

Transcript

  1. Email in Rails, and/or
    Introduction to the
    "Dark Depths of Email"
    Ryo Kajiwara(sylph01) @ Fukuoka.rb
    #149/150

    View full-size slide

  2. ୭ʁ
    sylph01 / ֿݪ ཾ
    Twitter: @s01
    ҉߸ͱ͔Ͱ͖·͢
    Elixirͱ͔Ͱ͖·͢
    Ruby·ΔͰΘ͔ΒΜ

    View full-size slide

  3. W3CͷձٞͰདྷ·ͨ͠
    ͍Ζ͍Ζweb-relatedͳεςοΧʔͱ
    ͔͋ΔͷͰ͋ͱͰ੠͔͚͍ͯͩ͘͞

    View full-size slide

  4. RailsͰϝʔϧͷ͢΂ͯ
    Λѻ͑ΔΑ͏ʹͳͬ
    ͨʂ

    View full-size slide

  5. MTAʮ΁ͷʯೖΓޱΛ
    උ͍͑ͯΔɺͱ͋Δ͚
    ͲɺͲͪΒ͔ͱ͍͏ͱ
    MTAʮ͔ΒͷʯೖΓޱ

    View full-size slide

  6. ͜Ε͸ԿΛ͢Δ΋ͷͧ
    • ड৴ϝʔϧΛActiveRecordΦϒδΣΫτʹม׵
    • ActiveStorageͰϥΠϑαΠΫϧ؅ཧɺҰఆظؒܦͬͨΒࣗಈম
    ٫ʢ࡟আʣ
    • ϝʔϧΛड͚ͨͱ͖ͷॲཧΛॻ͚Δ

    View full-size slide

  7. ݸਓͰϝʔϧ΍Δͷ͸͓͢͢
    Ί͠·ͤΜ
    • IMAP΍ΔͱετϨʔδ஍ࠈʹؕΓ·͢
    • ໎࿭ϝʔϧରࡦ͸͠ΜͲ͍
    • ઃఆϛεΔͱϝʔϧ͕૬खʹಧ͖·ͤΜ
    • ͱ͍͏͔SMTPΛ΍ΊΖ

    View full-size slide

  8. ͳͷͰGuidesʹॻ͍ͯ͋ΔΑ
    ͏ʹWebαʔϏεΛ࢖͓͏
    • Mailgun
    • Mandrill
    • Postmark
    • SendGrid
    • ·ͨ͸Amazon SESʢଞʹൺ΂Δͱࣗ෼ͰMTA؅ཧ͢Δͷʹۙ͘
    ͸͋Δʣ

    View full-size slide

  9. ͦΕͰ΋΍Γͨ͘ͳͬ
    ͨͱ͖ͷ࿩Λ͠·͢

    View full-size slide

  10. ஫: ͔͜͜ΒNot Ruby
    Rubyͷݴ༿ͰؤுΓ͔͚ͨͬͨͲؒ
    ʹ߹Θͳ͔ͬͨΑ…

    View full-size slide

  11. SMTP
    Ͳ͕͜Simple΍ͶΜMail Transfer Protocolɻ
    RFC 821 → ݱࡏͷ࠷৽͸ RFC 5321
    ʮϝʔϧΛόέπϦϨʔͷΑ͏ʹసૹ͢ΔʯͷͰʮSMTP
    relayingʯͱ͔ʮϦϨʔαʔόʔʯͱ͔͍͏͚ΕͲݱ୅తʹ͸͜ͷ
    Πϝʔδ͸࣋ͬͯͳͯ͘Α͍Ͱ͢ɻ૬खઌυϝΠϯ໊ͷMXϨίʔ
    υΛݟͯ௚઀ͦ͜ʹୟ͖͚ͭ·͢ɻ

    View full-size slide

  12. SMTPʹ͸ೝূ͕ͳ͍
    SMTP͸ϦϨʔػߏΛ࡞ΔͨΊͷϓϩτίϧͳͷͰɺͲ͔͜Βϝʔ
    ϧ͕དྷ͔ͨΛ͍͍ͪͪೝূ͢Δඞཁ͕ͳ͍ɻཧ۶͸Θ͔Δͷ͚ͩ
    Ͳ໎࿭ϝʔϧ͕͸ͼ͜Δ࠷େͷݪҼͷҰ͕ͭ͜Εɻ
    POP before SMTPɺSMTP-AUTHͳͲͷ֦ுͰೝূΛ͢Δɻ

    View full-size slide

  13. SPF, DKIM
    ͜ͷϝʔϧ͸ͪΌΜͱ͜ͷυϝΠϯΛॴ༗͍ͯ͠Δਓʢͷαʔ
    όʔʣ͔Βདྷͯ·͢Αɺͱ͍͏͜ͱΛ͍ࣔͨ͠ɻ
    ͲͪΒ΋DNSͷTXTϨίʔυʹهड़Λߦ͏ɻ
    • SPF: ڐՄ͢ΔIPΞυϨεΛࢦఆɻ
    • DKIM: ެ։伴ΛTXTϨίʔυʹઃఆɻαʔόʔ͸ൿີ伴Λར༻͠
    ͯϝοηʔδʹॺ໊͢Δɻ

    View full-size slide

  14. SPF
    TXTϨίʔυʹIPΞυϨεɺ΋͘͠͸MXϨίʔυͷυϝΠϯ໊Λࢦ
    ఆ͢Δ͚ͩɻ
    ྫ: example.net. IN TXT "v=spf1 ip4:192.0.2.1 -all"

    View full-size slide

  15. DKIM
    • opendkimΛΠϯετʔϧͯ͠ઃఆ͢Δ
    • ΍Δ͜ͱଟ͍ͷͰৄࡉ͸DigitalOceanͷνϡʔτϦΞϧࢀর -
    https:/
    /www.digitalocean.com/community/tutorials/how-to-
    install-and-configure-dkim-with-postfix-on-debian-wheezy
    • ެ։伴ɾൿີ伴ϖΞͷੜ੒ͱTXTϨίʔυͷੜ੒Λ΍ͬͯ͘
    ΕΔ

    View full-size slide

  16. DMARC
    • ϔομʹࣔ͞ΕΔૹ৴ऀͷυϝΠϯ(Header-From)ͱMAIL FROM
    ίϚϯυͰ౉͞ΕΔૹ৴ऀͷυϝΠϯ(Envelope-From)ͷҰகΛ
    औΔ
    • Header-FromͷυϝΠϯ໊ͱDKIMͷ"d="Ͱ༩͑ΒΕΔυϝΠϯ
    ໊ͷҰகΛऔΔ
    ͱ͍͏௥ՃͷೝূΛ͢Δɻࣦഊͨ͠৔߹ʹυϝΠϯΦʔφʔʹ໰
    ୊ͷ͋ΔϝʔϧΛใࠂͰ͖Δ࢓૊Έ΋͋Δɻ

    View full-size slide

  17. SPF, DKIM, DMARCͷઃ
    ఆϛε͸͔ͳΓଟ͍
    αʔϏε࢖ͬͯͯ΋DNSઃఆ๨ΕΔͱ
    ໎࿭ϝʔϧѻ͍͞Ε·͢

    View full-size slide

  18. ड৴͢Δଆͱͯ͠͸
    ʮ໎࿭ϝʔϧ͸ड৴
    ϘοΫεʹೖͬͨ࣌఺
    Ͱෛ͚ʯ
    MTAͰݕূͪΌΜͱ͠Α͏

    View full-size slide

  19. ૹΔଆͰؾΛ͚ͭͳ
    ͖Ό͍͚ͳ͍͜ͱ

    View full-size slide

  20. LTͩͱೖΓ੾Βͳ͍ͷ
    Ͱ؆୯ʹ঺հ

    View full-size slide

  21. GoogleͷҰׅૹ৴ΨΠυϥΠ
    ϯ
    https:/
    /support.google.com/a/answer/81126?hl=ja
    ૹΔଆ͸͜Εकͬͯͳ͍ͱ͍ͭͷؒʹ͔໎࿭ϝʔϧϑΥϧμߦ͖
    ʹͳΓ·͢ɻ
    ૹ৴ϘϦϡʔϜ͕େ͖͍৔߹͸Postmaster ToolsΛ࢖͏ͱΑ͍ɻ

    View full-size slide

  22. mail-tester.com
    https:/
    /www.mail-tester.com/
    ͜͜ʹϝʔϧૹΔͱIP͕ϒϥοΫϦετ͞ΕͯΔ͔Ͳ͏͔΍Ұൠ
    తͳઃఆϛεʹ͍ͭͯڭ͑ͯ͘ΕΔɻ

    View full-size slide

  23. DigitalOcean͔Βૹͬͯ
    ͨΒMSNʹϒϩοΫ͞
    ΕͯͨͰ͟͝Δ

    View full-size slide

  24. چWILLCOMܥͷΞυϨ
    εʹ͸௨৴͢Βड͚෇
    ͚ͯ΋Β͑ͳ͔ͬͨ

    View full-size slide

  25. ݸਓͰϝʔϧ΍Δͷ͸͓͢͢
    Ί͠·ͤΜ(࠶)
    • IMAP΍ΔͱετϨʔδ஍ࠈʹؕΓ·͢
    • ໎࿭ϝʔϧରࡦ͸͠ΜͲ͍
    • ઃఆϛεΔͱϝʔϧ͕૬खʹಧ͖·ͤΜ
    • ͱ͍͏͔SMTPΛ΍ΊΖ

    View full-size slide

  26. ͳͷͰWebαʔϏεΛ࢖͓͏
    (࠶)
    • Mailgun, Mandrill, Postmark, SendGrid, Amazon SES
    • αʔόʔӡ༻Λؙ౤͛Ͱ͖Δ͠
    • ໎࿭ϝʔϧରࡦ΍ͬͯ͘ΕΔ
    • IPΞυϨεͷϨϐϡςʔγϣϯ؅ཧ΋΍ͬͯ͘ΕΔ

    View full-size slide

  27. Ͳ͏ͯ͠΋΍Γ͍ͨ
    ํʹ͸
    ΋͏ͪΐͬͱ౿ΈࠐΜͩ಺༰Λ"Dark
    Depths of SMTP"(ٕज़ॻయ4ॳग़)ͱ͍͏
    ຊͰॻ͍͍ͯ·͢
    ͜ͷ෼໺͸঎ۀຊ͕࠷ۙग़ͯͳ͍ͷͰ͓
    ͦΒ͘࠷৽Ͱ͢
    ͳ͓౦ํཁૉ͸දࢴ͚ͩͰ͢ɻ

    View full-size slide

  28. Welcome to
    SMTPপ

    View full-size slide