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

SendGrid Web API

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for ktsuda ktsuda
September 15, 2016
760

SendGrid Web API

難しいメール送信を手軽に

Avatar for ktsuda

ktsuda

September 15, 2016
Tweet

Transcript

  1. ϝʔϧͷ࢓ࣄ͸େม » ISPͷBlocklist » ೝূ » SPF: ૹ৴ݩIPΞυϨεΛ֬ೝɻ » DKIM:

    ిࢠॺ໊Λ෇༩͠ૹ৴ݩ͕ਖ਼౰͔ݕূɻ » DMARC: SPF/ DKIM྆ํʹࣦഊͨ͠৔߹ͷϧʔϧɻ
  2. SendGrid » Ϋϥ΢υϕʔεͷSMTPαʔϏε » ղܾ͢Δͷ͸… » ΤϯδχΞͷۤ೰ » Ϛʔέολͷۤ೰ »

    ड৴ऀͷۤ೰ » ͦͷ݁Ռ… Ϗδωεʹूத // ΑΓॏཁͳ࣮૷ʹूத
  3. SMTP Transport $ telnet smtp.sendgrid.net 587 $ openssl s_client -connect

    smtp.sendgrid.net:465 » High Latency αʔόͱͷ΍ΓऔΓ͕ଟ͍
  4. SMTP Transport 220 SG ESMTP service ready at ismtpd0017p1sin1.sendgrid.net 250-smtp.sendgrid.net

    250-8BITMIME 250-PIPELINING 250-SIZE 31457280 250-STARTTLS 250-AUTH PLAIN LOGIN 250 AUTH=PLAIN LOGIN 334 VXNlcm5hbWU6 334 UGFzc3dvcmQ6 235 Authentication successful 250 Sender address accepted 250 Recipient address accepted 354 Continue 250 Ok: queued as sS0HQxlITZWHC4Q4BrLInw 221 See you later
  5. SMTP require 'mail' require 'smtpapi' # sendgrid/smtpapi-ruby smtapi = Smtpapi::Header.new

    ... mail = Mail.new(charste: UTF-8) do ... end mail['X-SMTPAPI'] = smtpapi.to_json mail.delivery_method(:smtp, address: 'smtp.sendgrid.net', port: 587, domain: 'gmail.com', authentication: :login, user_name: sendgrid_username, password: sendgrid_password) Ѽઌ100݅Ͱ7ඵ
  6. Web API v2 curl -X POST https://api.sendgrid.com/api/mail.send.json \ -H "Authorization:

    Bearer ${SENDGRID_API_KEY}" \ -d [email protected] \ -d [email protected] \ -d subject="Hello Word" \ -d text="This is a test email. Delete me whenever you like." \ -d headers='{"X-SMTPAPI":"{\"to\":[\"[email protected]\",...]}"}' Ѽઌ100݅Ͱ4ඵ
  7. Libraries » sendgrid/sendgrid-nodejs » sendgrid/sendgrid-php » sendgrid/sendgrid-python » sendgrid/sendgrid-go »

    sendgrid/sendgrid-ruby » sendgrid/sendgrid-csharp » sendgrid/sendgrid-cobol » sendgrid/sendgrid-perl
  8. Web API v3 ग़·ͨ͠! ͞Βʹૉૣ࣮͘૷ curl -X POST https://api.sendgrid.com/v3/mail/send \

    -H "Authorization: Bearer ${SENDGRID_API_KEY}" \ -H "Content-Type: application/json" \ -d @data.json ͪ͜Β΋ɺѼઌ100݅Ͱ4ඵ
  9. data.json { "personalizations": [ { "to": [ { "email": "[email protected]"

    }, ... ], "subject": "Hello, World" } ], "from": { "email": "[email protected]" }, ...
  10. ... "content": [ { "type": "text/plain", "value": "This is a

    test email. Delete me whenever you like." } ] } JSONͷόϦσʔτ ৄ͘͠͸ͪ͜Βɻ https://sendgrid.com/docs/APIReference/WebAPI_v3/Mail/ index.html
  11. ศརػೳ » Event Webhook ൃੜͨ͠Πϕϯτ৘ใΛࢦఆͨ͠URLʹPOST ྫ) ϩάղੳج൫ » Inbound Parse

    Webhook ड৴ͨ͠ϝʔϧΛࢦఆͨ͠URLʹPOST ྫ) ࣗࣾΞϓϦέʔγϣϯͰϝʔϧΛड৴ ྫ) ϝʔϧΛτϦΨʔʹ