我不能使用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'))

错误,链接图像

让我们看一下文档。

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

查看文档获取更多信息。

最新更新