IT Knowledge Base

~ Freedom is the right of all sentient beings ~

發佈日期:

分類:

,

如何利用Web API:cURL測試SendGrid服務

01. 利用第三方的服務,出問題時需要除錯是一件苦差。特別是問題出在自己設定,定是第三方身上,往往要花大量時間。

02. SendGrid提供不少Web API程式,令開發時幫助不少。更重要是可以測試自己SendGrid是否可以成功執行。

03. 今次就用cURL測試一下,究竟是否能成功在伺服器,利用SendGrid API Key發送電郵。

04. 登入SendGrid帳戶。

05. 在左邊目錄選擇『Email API』、『Integration Guide』,再在右邊選擇『Web API』。

06. 選擇『cURL』。

07. 設定新的SendGrid API Key,再按『Create Key』。下面便會出現cURL程式碼。

08. 在伺服器上打開『終端機』,執行之前複製的cURL程式碼。

export SENDGRID_API_KEY='<Your SendGrid API Key>'
curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header "Authorization: Bearer $SENDGRID_API_KEY" \
--header 'Content-Type: application/json' \
--data '{"personalizations": [{"to": [{"email": "receiver@example.com"}]}],"from": {"email": "sender@example.com"},"subject": "Sending with SendGrid is Fun","content": [{"type": "text/plain", "value": "and easy to do anywhere, even with cURL"}]}'

09. 返回SendGrid網頁,勾選『I’ve executed the code above』,再按『Next: Verify Integration』。

10. 按『Verify Integration』作出驗證。

11. 如見到此畫面,即代表SendGrid設定正確無誤。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *