问题
I need to integrate mail service in my application. My application should send the email, which has to attach a .pdf file (detailed report). PDF file is now at remote server.
Can anyone help me to understand how to send mail with pdf attachment in blackberry? If, it is feasible to implement then how would i go with this?
Below are the links, I have got from Blackberry knowledge base forum for sending mail in blackberry
How To - Create an attachment
How To - Create and send messages
回答1:
I believe this is the updated version of the first link in your question.
In your case, you want to send a PDF document, so you would replace the content-type with application/pdf
, and the filename could be DetailedReport.pdf
, or whatever you like. This filename is not a full path. Just a name that will be seen by the recipient of the email.
SupportedAttachmentPart attach = new SupportedAttachmentPart(multipart,
"application/pdf", "DetailedReport.pdf", data);
The byte[]
is something you have to read in yourself, opening the local pdf file (wherever you stored it). It's just the binary data from the file, so I'd use a DataInputStream
:
String fileUrl = "file:///SDCard/BlackBerry/SomePath/DetailedReport.pdf";
FileConnection fileConn = (FileConnection)Connector.open(fileUrl, Connector.READ);
int fileSize = fileConn.fileSize();
byte[] data = new byte[fileSize];
DataInputStream input = fileConn.openDataInputStream();
input.read(data);
And of course, I would recommend doing this work on a background thread to avoid freezing your UI.
来源:https://stackoverflow.com/questions/11117075/sending-email-with-pdf-attachment-in-blackberry