1

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');
});
user
  • 345
  • 2
  • 8
  • 32
  • 1
    Can you post a link to the .pkpass bundle you have generated? What is the file size? When you try to open on a device, what does the console log show as the reason for not opening it? – PassKit Jun 10 '20 at 04:57
  • The console doesn't log any errors it just shows the error I posted above on the device. I have updated the question with the wallet kit URL & the file size is "Zero KB" which now that I'm reading is probably the reason it's not working @PassKit – user Jun 10 '20 at 07:05
  • @PassKit can you please help me or offer any advice? – user Jun 11 '20 at 04:09
  • 1
    This is a node.js problem and I am not a node expert. My guess is you need to send the bytes from your stream not the raw steam object. – PassKit Jun 11 '20 at 04:11

0 Answers0