我正在使用sendgrid smtp发送电子邮件,并且总是收到针对该请求的未经授权的错误。 我在这里https://sendgrid.com/docs/for-developers/sending-email/api-getting-started/关注了文档。 我应该从终端登录还是类似的登录?
const sendFunc = () => {
return fetch('https://api.sendgrid.com/v3/mail/send', {
method: 'Post',
mode: 'no-cors',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {my apiKey-here}'
},
data: { "personalizations": [{ "to": [{ "email": "mahmoudnafea19@gmail.com", "name": "John Doe" }], "subject": "Hello, World!" }], "content": [{ "type": "text/plain", "value": "Heya!" }], "from": { "email": "mahmoud.m.elsayed19@gmail.com", "name": "Sam Smith" }, "reply_to": { "email": "sam.smith@example.com", "name": "Sam Smith" } }
}).then((response) => console.log(response)).catch((err) => console.log(err))
}
答案 0 :(得分:0)
我必须将数据和标头作为对象传递给函数调用之外