I'm trying to create an i-cal event and attach it to a sparkpost transmission like this:
const event = cal.createEvent({
start: req.body.a.start,
end: req.body.a.end,
summary: req.body.a.title,
description: req.body.a.body,
url: Config.get('/sparkpost/app'),
});
// create event organizer
event.organizer({
name: 'Test',
email: '[email protected]',
mailto: '[email protected]'
})
// add an alarm
event.createAlarm({
type: 'display',
trigger: 900, // 30min before event
});
req.body.a.teammates.map(async (a) => {
await event.createAttendee({email: a})
})
b64Event = base64.encode(event)
req.body.a.teammates.map(async (b) => {
client.transmissions.send({
recipients: [{address: b}],
content: {
from: Config.get('/email/fromEmail'),
subject: req.body.a.title,
text: req.body.a.body,
attachments: [{name: "Test Event", type:"ics", data: [base64.encode(event)]}]
},
options: {sandbox: false}
}).then(data => {console.log(data);}).catch(err => {console.log(err);});
})
Everything seems to work. Except: I cannot get sparkpost to send this file. Keep getting an error:
{ SparkPostError: Unprocessable Entity
at createSparkPostError (C:Sonar
ode_modulessparkpostlibsparkpost.js:38:15)
at Request._callback (C:Sonar
ode_modulessparkpostlibsparkpost.js:128:15)
at Request.self.callback (C:Sonar
ode_modules
equest
equest.js:185:22)
at Request.emit (events.js:182:13)
at Request.<anonymous> (C:Sonar
ode_modules
equest
equest.js:1154:10)
at Request.emit (events.js:182:13)
at IncomingMessage.<anonymous> (C:Sonar
ode_modules
equest
equest.js:1076:12)
at Object.onceWrapper (events.js:273:13)
at IncomingMessage.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1094:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
name: 'SparkPostError',
errors:
[ { message:
'field 'content.attachments[0].data' value '["W29iamVjdCBPYmplY3Rd"]' is of type 'json_array
' but needs to be of type 'string'',
code: '1300' } ],
statusCode: 422 }
I also tried it without the Base64.encoding, and got the same error. Sparkpost doesn't offer a lot of examples or advice, so I am blocked... Please any suggestions??
question from:
https://stackoverflow.com/questions/65951382/can-i-send-ics-file-with-sparkpost-node-js 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…