我編寫了將附件從我的BlackBerry設備發送到我的Gmail帳戶的代碼。無法發送帶附件的郵件
郵件發送時沒有錯誤。但問題是附件部分不起作用。該消息根本不包含我的依戀!
請幫我解決這個問題。
Multipart mp = new Multipart(); byte [] data = readFile(strFileName); String fileData =「只是一個簡單的測試」; 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());
}
顯示你的代碼的其他代碼進行比較。 – oxigen 2011-03-31 10:14:37