以下是我的javamail代码:
- Java code
message.setText("this just for test");message.setSubject("For test");Multipart m = new MimeMultipart();BodyPart body = new MimeBodyPart();DataSource source = new FileDataSource(new File("E:\\path.txt"));body.setDataHandler(new DataHandler(source));m.addBodyPart(body);message.setContent(m, "file");message.setSentDate(new Date()); Transport.send(message);
结果是:
"this just for test" 这句话丢失了,并且邮件的正文被替换成可附件文本的内容,请问这是为什么啊?
------解决方案--------------------
需要设置bodypart.setFimeName