簡體   English   中英

我不能使用sendgrid。 我無法發送 email

[英]I cant use sendgrid . I cant send the email

發送 email 的代碼

const message = {
to: 'ayelenwf@gmail.com',
from : 'ayee_01@live.com',
subject: 'hola, estoy probando',
text: 'como va todo?',
html:'<h1>holis</h1>'
}
------------------------------------------------
sgMail.send(message)
.then((response) => console.log('email sent...')).
catch((err)=>console.log(err, 'error'))

錯誤,鏈接圖片

讓我們看一下文檔

  1. 首先,您必須在 SendGrid 控制台中驗證您的發件人身份。 這通常通過 DNS 驗證域范圍的身份,或通過回答 email 驗證 email 地址特定的發件人來完成。

  2. 然后,創建 SendGrid API 密鑰。 您應該確保您的密鑰保持私密,並且僅限於電子郵件發送,除非您的應用程序需要更多功能。

  3. SendGrid 提供了用於發送電子郵件的示例代碼。 這里是:

    const sgMail = require('@sendgrid/mail')
    sgMail.setApiKey(process.env.SENDGRID_API_KEY)
    const msg = {
      to: 'test@example.com', // Change to your recipient
      from: 'test@example.com', // Change to your verified sender
      subject: 'Sending with SendGrid is Fun',
      text: 'and easy to do anywhere, even with Node.js',
      html: '<strong>and easy to do anywhere, even with Node.js</strong>',
    }
    sgMail
      .send(msg)
      .then(() => {
        console.log('Email sent')
      })
      .catch((error) => {
        console.error(error)
      })

查看文檔以獲取更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM