我正在使用Google Cloud Functions上的@ sendgrid / mail模块。
我的邮件的格式如下:
{
to: user.email,
from: user.fromail,
cc: user.tl_email,
subject: 'Test',
html: setTemplate(),
attachments: [{
filename: 'test.png',
content: test,
content_id: 'test',
disposition: 'inline'
},
...]
};
我有一系列带有不同的“收件人”和不同的html电子邮件的邮件。
当我使用sgMail.send(emailsArray)而user.email只是我时,邮件将被发送。
当我使用sgMail.send(emailsArray)和user.email时,它们之间出现错误:
{ Error: Unauthorized
at Request.http [as _callback] (node_modules/@sendgrid/client/src/classes/client.js:124:25)
at Request.self.callback (node_modules/request/request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (node_modules/request/request.js:1161:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
code: 401,
message: 'Unauthorized',
response:
{ headers:
{ server: 'nginx',
date: 'Fri, 16 Aug 2019 08:00:04 GMT',
'content-type': 'application/json',
'content-length': '74',
connection: 'close',
'access-control-allow-origin': 'https://sendgrid.api-docs.io',
'access-control-allow-methods': 'POST',
'access-control-allow-headers': 'Authorization, Content-Type, On-behalf-of, x-sg-elas-acl',
'access-control-max-age': '600',
'x-no-cors-reason': 'https://sendgrid.com/docs/Classroom/Basics/API/cors.html' },
body: undefined } }
有帮助吗?