I'm generating the pkpass
successfully server-side and now I'm trying to send the pkpass
via email. I'm using nodemailer to try and do this but when I try to open the pass after downloading it from the sent email I get this error The pass "Event.pkpass" could not be opened.
The pass can be opened via my app and works fine. What am I doing wrong?
Pass Url: shoebox://card/Q03UycwVF9DPkMG6ytNw+DviZ6A=
Generating the PKPass:
try {
const examplePass = await createPass({
model: "./models/Event.pass",
certificates: {
wwdr: "./models/certs/wwdrc.pem",
signerCert: "./models/certs/signerCert.pem",
signerKey: {
keyFile: "./models/certs/signerKey.pem",
passphrase: "54321"
}
},
overrides: {
// keys to be added or overridden
serialNumber: serialNumber
}
});
examplePass.barcode("36478105430"); // Random value
examplePass.headerFields.push({
label : "EVENT",
key : "title",
value : title
});
examplePass.primaryFields.push({
key : "date",
label : "DATE",
value : date
});
examplePass.secondaryFields.push({
key : "location",
label : "LOCATION",
value : location
});
// Generate the stream, which gets returned through a Promise
const stream = examplePass.generate();
res.set({
"Content-Type": "application/vnd.apple.pkpass",
"Content-disposition": `attachment; filename=${passName}.pkpass`
});
stream.pipe(res);
Sending the email:
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
requireTLS: true,
auth: {
user: 'email@gmail.com',
pass: 'password'
}
});
let mailOptions = {
from: 'email@gmail.com',
to: userEmail,
subject: "You're on your way to ",
html: '<h1>Testing email</h1>',
attachments: [
{
filename: 'Event.pkpass',
contentType: 'application/vnd.apple.pkpass',
content: stream
}
]
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error.message);
}
console.log('success');
});