I write code for sending mail with attachment from my BlackBerry device to my gmail account.
The mail is sent without an error. But the problem is the attachment part is not working. The message simply doesn't contain my attachment!
Please help me to solve the issue.
Multipart mp = new Multipart(); byte[] data = readFile(strFileName); String fileData = "just a simple test"; String messageData = msgField.getText(); SupportedAttachmentPart sap= null;
try{
sap = new SupportedAttachmentPart(mp,"application/x-example",strFileName, data);
}catch (Exception e) {
Dialog.inform(e.toString());
}
TextBodyPart tbp = new TextBodyPart(mp,messageData);
mp.addBodyPart(tbp);
mp.addBodyPart(sap);
Folder[] folders = Session.getDefaultInstance().getStore().list(Folder.SENT);
Message message = new Message(folders[0]);
try{
Address toAdd = new Address(toField.getText(), toField.getText());
Address[] toAdds = new Address[1];
toAdds[0] = toAdd;
message.addRecipients(Message.RecipientType.TO,toAdds);
message.setSubject(subjectField.getText());
message.setContent(mp);
Transport.send(message);
}catch (Exception e){
Dialog.inform(e.toString());
}