微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我不能使用 sendgrid 我无法发送电子邮件

如何解决我不能使用 sendgrid 我无法发送电子邮件

发送电子邮件代码

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'))

the error,link image

解决方法

让我们来看看 documentation

  1. 首先,您必须在 SendGrid 控制台中验证您的发件人身份。这通常是通过域范围身份的 DNS 验证来完成的,或者通过回复特定于电子邮件地址的发件人的验证电子邮件来完成。

  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)
      })

Check in the docs for more info.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。