我不能使用 sendgrid 。我无法发送电子邮件
I cant use sendgrid . I cant send the email
code to send the 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'))
the error, link image
我们来看看documentation。
首先您必须在 SendGrid 控制台中验证您的发件人身份。这通常是通过对域范围内的身份进行 DNS 验证,或通过回复针对特定电子邮件地址的发件人的验证电子邮件来完成的。
然后,您创建 SendGrid API 密钥。您应该确保您的密钥保持私密并且仅限于电子邮件发送,除非您的应用程序需要更多功能。
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)
})
code to send the 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'))
the error, link image
我们来看看documentation。
首先您必须在 SendGrid 控制台中验证您的发件人身份。这通常是通过对域范围内的身份进行 DNS 验证,或通过回复针对特定电子邮件地址的发件人的验证电子邮件来完成的。
然后,您创建 SendGrid API 密钥。您应该确保您的密钥保持私密并且仅限于电子邮件发送,除非您的应用程序需要更多功能。
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)
})