短信作为文本文件附在信中。我不明白为什么会这样。
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();
}
}
答案 0 :(得分:1)
这是因为您首先附加原始邮件,并在原始邮件之后附加回复文本。大多数邮件程序都会将回复文本显示为附件。首先放置回复文本。此外,原始邮件通常不会作为回复的附件添加。通常,原始邮件的文本包含在答复的文本中。请参阅composing the reply text的此JavaMail FAQ条目以及finding the main body text in the original message的此JavaMail FAQ条目。