Laravel with SendGrid

Laravel with SendGrid

Laravel勉強会 2016/6/17 発表資料

7b41309d419e0ac011d14774067b0be1?s=128

s-ichikawa

June 16, 2016
Tweet

Transcript

  1. Laravel with SendGrid 2016.5.17

  2. I am … Twitter: @ichikawa_0829 ▸ ϑϦʔϥϯε ▸ dots.

  3. What is SendGrid?

  4. What is SendGrid ▸ ϝʔϧ഑৴Λߦ͏ͨΊͷΫϥ΢υαʔϏε ▸ ΞΧ΢ϯτൃߦ͢Ε͹͙͢ʹSMTP઀ଓɺWeb(REST) APIɺϚʔέ ςΟϯάϝʔϧػೳΛ࢖ͬͯϝʔϧΛૹ৴Ͱ͖Δ ▸

    ແྉ࿮͕͋Δ(ແྉͰ400௨/೔) ▸ SMTP APIͱ͍͏ػೳ͕ศར ▸ ։෧΍ΫϦοΫͷΠϕϯτΛHookͰ͖Δ ▸ ؅ཧը໘͔Β༷ʑͳ౷ܭ৘ใ͕ࢀরՄೳ About
  5. None
  6. None
  7. In Laravel

  8. LaravelͰϝʔϧΛૹ৴͢Δ৔߹ ▸ SendGridͷSMTPαʔόΛ࢖͏ ▸ WebAPIΛ࢖͏ In Laravel

  9. SendGridͷSMTPαʔόΛ࢖͏ ▸ ެࣜHP Ͱ͸LaravelͰૹ৴͢Δํ๏ͱͯ͠ɺ͜ͷํ๏͕঺հ ͞Ε͍ͯ·͢ ▸ config/mail.phpʹSendGridͷSMTPαʔό΁ͷ઀ଓ৘ใΛ ࢦఆ͢Δ͚ͩɻ ▸ ؆୯ʂ

    In Laravel
  10. <?php return array( 'driver' => 'smtp', 'host' => 'smtp.sendgrid.net', 'port'

    => 587, 'from' => array('address' => 'from@example.com', 'name' => 'John Smith'), 'encryption' => 'tls', 'username' => 'sendgrid_username', 'password' => 'sendgrid_password', ); config/mail.php In Laravel SendGridͷSMTPαʔόΛ࢖͏
  11. Web APIΛ࢖ͬͯϝʔϧΛૹ৴͢Δ৔߹ ▸ SendGridͷ΄΅શͯͷػೳ͸WebAPIܦ༝Ͱ࢖༻͢ΔͨΊ ͷΤϯυϙΠϯτ͕༻ҙ͞Ε͍ͯΔ ▸ curl΍ެࣜϥΠϒϥϦɺίϛϡχςΟϕʔεϥΠϒϥϦΛ࢖ ༻ͯ͠ϦΫΤετ౤͛Δ ▸ SendGridͷSMTPαʔόΛ࢖͏ΑΓॲཧ͕ૣ͘ऴΔέʔε͕

    ଟ͍ͷͰՄೳͳΒ͹Web APIΛ࢖͏͜ͱ͕ਪ঑͞Ε͍ͯΔ In Laravel
  12. ૣ͘ͳΔՄೳੑ͕͋ΔͳΒWebAPI࢖͍͍ͨ (͔͠΋Կނ͔֎ʹ޲͔ͬͯSMTP઀ଓग़དྷͳ͍͠…)

  13. ެࣜϥΠϒϥϦΛ࢖ͬͯΈΔ ▸ sendgrid/sendgrid-php ΛcomposerͳͲͰΠϯετʔϧ͢ Δ ▸ $sendgrid = new SendGrid('YOUR_SENDGRID_APIKEY');

    ▸ $email = new SendGrid\Email(); ▸ $email->addTo('test@example.com'); // ͱ͔৭ʑઃఆ͢Δ ▸ $sendgrid->send($email); In Laravel
  14. ΋͏ͪΐͬͱLaravelͬΆ͘΍Γ͍ͨͳ͊…

  15. ΋͏ͪΐͬͱLaravelͬΆ͘΍Γ͍ͨͳ͊… (ͩͬͯMail::send()Ͱॻ͍ͯ͋Δطଘίʔυ͕୔ࢁɻɻɻ)

  16. ଞΛ୳ͯ͠΋ݟ౰ͨΒͳ͍ɻɻɻ

  17. ࡞ͬͪΌ͓ʂ

  18. ϝʔϧपΓͲ͏ͳͬͯΔʁ ▸ mail.driverͷઃఆʹ߹ΘͤͨTransportΫϥεΛ࣋ͭ SwiftMailerΛ$app['swift.mailer']ʹొ࿥ ▸ $app['swift.mailer']Λ࣋ͭIlluminate\Mail\Mailerͱ͍͏Ϋϥ εʹ৭ʑઃఆΛߦ͍$app['mailer']ʹొ࿥ ▸ Illuminate\Support\Facades\MailͰ$app['mailer']Λొ࿥ ࡞ͬͪΌ͓ʂ

  19. ҙ֎ͱ࡞ΕΔ͔΋ ▸ ཁ͸SendGrid༻ͷTransportΫϥε࡞Ε͹OK (࣮ࡍ͸ͦΕΛ ొ࿥͢ΔҝͷTransportManagerͱɺMailServiceProvider΋ ඞཁ) ▸ Mandrill΍MailgunͷιʔεݟͨΒGuzzleHttp\ClientͰ POSTͯ͠Δ͚ͩ ▸

    ΠέΔʂΠέΔͧʂ ࡞ͬͪΌ͓ʂ
  20. laravel-sendgrid-deriver https://packagist.org/packages/s-ichikawa/laravel-sendgrid-driver

  21. laravel-sendgrid-driver ▸ ଞͷdriverͱಉ༷ɺconfigϑΝΠϧʹز͔ͭઃఆΛ௥Ճ͢Ε ͹OK ▸ SendGridΛศརʹ࢖͏ͨΊʹ͔ܽͤͳ͍SMTP API΋࢖͑Δ Α͏ʹ͠·ͨ͠ ▸ MailServiceProvider΍TransportManager͸ݩͷ΋ͷΛܧঝ

    ͯ͠ΔͷͰଞͷdriver΋ͦͷ··࢖͑Δ ࡞ͬͪΌ͓ʂ
  22. ࡞ͬͪΌ͓ʂ 3/1 ॳPull Request 5/17 500install 5/25 1000install 5/13 N.Yͷਓ͔Β࣭໰

    6/13 2000install
  23. ·ͱΊ ▸ ύοέʔδ։ൃ͸Laravelͷ͍͍ษڧʹͳΓ·ͨ͠ ▸ SendGridศརɻLaravelͰ࢖͏ͳΒlaravel-sendgrid-driver ࢼ͍͚ͯͨͩ͠Δͱخ͍͠Ͱ͢ɻ(Կ͔͋Ε͹༏͘͠PRΛ…) ▸ ެ։ͨ͠෺ʹ͍ͭͯͷ࣭໰΍PullRequest͸΍ͬͺΓӳޠ͕ ଟ͍ɻӳޠ͕Μ͹Ζ͏… ▸

    composer require Ͱࣗ෼ͷύοέʔδ͕ೖΔͷخ͍͠ɻ ࢖ͬͯ΋Β͑Δͱࣗ৴ʹ΋ͳΔɻ
  24. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠