Deborah Miller
Deborah Miller

Reputation: 1

Cannot Open Streamed File Attachment

Via a Domino Java agent, I use Apache POI to generate an Excel spreadsheet. The code first saves the file to a drive; I've verified I can open the file there and the file contains information. However, when I attach it to an email message through MIME, I get a message stating "Excel cannot open the file spreadsheet.xlxs" and "file format or file extension is not valid".

Here's the code I'm using:

MIMEEntity ebody = maildoc.createMIMEEntity();
Stream outStream = session.createStream();
Stream inStream = session.createStream();
inStream.open(entry.getValue(),"binary");

do {
byte[] buffer = inStream.read(32767);
outStream.write(buffer);
} while(!inStream.isEOS());

inStream.close();

MIMEEntity child = ebody.createChildEntity();
child.setContentFromBytes(outStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", MIMEEntity.ENC_IDENTITY_BINARY);
MIMEHeader cdHeader = child.createHeader("Content-Disposition");
cdHeader.setHeaderVal("attachment; filename="spreadsheet.xlxs");
MIMEHeader idHeader = child.createHeader("Content-ID");
idHeader.setHeaderVal("spreadsheet.xlxs");

outStream.truncate();
outStream.close();

Any ideas where I went wrong?

Upvotes: 0

Views: 135

Answers (1)

ths
ths

Reputation: 2942

xlsx, not xlxs. you have a typo.

Upvotes: 1

Related Questions