问题描述
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'))
解决方法
让我们来看看 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)
})