1
我設置的短信附加爲信中的文本文件。我不明白爲什麼會發生。Java郵件。回覆信息分離爲信息和附件
public void sendEmail(MimeMessage message, String textMessage){
Session session = getSession();
Transport transport = null;
BodyPart part = new MimeBodyPart();
MimeMultipart multipart = new MimeMultipart();
try {
String recipients = InternetAddress.toString(message.getRecipients(Message.RecipientType.TO));
MimeMessage replyMessage = (MimeMessage) message.reply(false);
replyMessage.setSubject("RE: " + message.getSubject());
replyMessage.setFrom(new InternetAddress(APPROVER));
replyMessage.setReplyTo(message.getReplyTo());
replyMessage.addRecipients(Message.RecipientType.TO, recipients);
part.setContent(message.getContent(), message.getContentType());
multipart.addBodyPart(part);
part = new MimeBodyPart();
part.setText(textMessage);
multipart.addBodyPart(part);
replyMessage.setContent(multipart);
transport = session.getTransport("smtp");
transport.connect(SERVER_HOST, APPROVER, APPROVER_PASSWORD);
transport.sendMessage(replyMessage, replyMessage.getAllRecipients());
} catch (IOException|MessagingException e) {
e.printStackTrace();
}
}
目前尚不清楚你想要做什麼。您是否嘗試將原始郵件附加到回覆郵件中?您創建的第一個MimeBodyPart永遠不會添加到MimeMultipart。這[JavaMail FAQ條目](http://www.oracle.com/technetwork/java/javamail/faq/index.html#forward)可能會有所幫助。 –
比爾感謝您的回覆。我嘗試回覆收到的消息。但是我的回覆信息附加爲原始信息的文件。對不起,複製粘貼錯誤。在代碼中修復。 –