我正在使用函数将图像附加到电子邮件。Android邮件无意使用Android Mail API
public void addAttachment(String filename) throws Exception {
BodyPart messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
_multipart.addBodyPart(messageBodyPart);
}
我在将图像附加到电子邮件时调用此函数。 当我尝试删除附件时,它是不可能的。
public void removeAttachment(String filename) throws Exception {
BodyPart messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
_multipart.removeBodyPart(messageBodyPart);
}
尝试使用此功能,但不工作。
public void AddAndRemoveAttachment(String filename, Boolean yesorno)throws Exception{
BodyPart messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
if(yesorno == true){
source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
_multipart.addBodyPart(messageBodyPart);
}
else{
_multipart.removeBodyPart(messageBodyPart);
}
}
但removeBodyPart没有删除附加的图像。 期待您的回复。 谢谢。
感谢,你能给我一个例子,用新功能看编辑的问题,但没有工作。 – Mukunda 2012-02-03 11:26:13
对不起,给我一些时间,我现在绝对忙碌... – herom 2012-02-03 11:48:58
也许这会帮助一点点:http://javamail.kenai.com/nonav/javadocs/javax/mail/Multipart.html – herom 2012-02-03 11:56:01