SendGrid

Email 服務,可以用來綁定 domain 並發送與接收郵件

因為目前 mailgun 免費版只有試用期間,之後都要付費,所以如果只是要測試暫時只能選擇 sendgrid,sendgrid 目前無提供 POP server 服務,所以無法使用 gmail 設置來收取綁定在 sendgrid 服務上的 domain 信件。

設置完後要去域名服務那邊設置三個 CNAME

發送郵件範例

const sgMail = require('@sendgrid/mail')
sgMail.setApiKey("...")
const msg = {
  to: '', // Change to your recipient
  from: '', // Change to your verified sender
  subject: '',
  text: '',
  html: '<strong>Node.js</strong>',
}
sgMail
  .send(msg)
  .then(() => {
    console.log('Email sent')
  })
  .catch((error) => {
    console.error(error)
  })

接收郵件範例

SendGrid 只能串接 server 使用 webhook 來接收郵件。

新增兩個

然候新增 inbound url:

之後寄信到 ...@parse.domain.com 都會發送 POST (multipart/form-data) 到上面的 URL

Node.js inbound email 接收範例

記得要寄信到 mx 設置的 subdomain

因為是 multipart/form-data 所以用 busboy 模組解析

Last updated

Was this helpful?