使用JavaMail转发邮件
基本代码如下:
Message forward = new MimeMessage(m_session);
forward.setSubject("转发:" + msg.getSubject());
forward.setFrom(new InternetAddress(this.from));
forward.addRecipient(Message.RecipientType.TO, new InternetAddress(this.to));
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("这是转发邮件,原文如下:\n\n");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
messageBodyPart.setDataHandler(msg.getDataHandler());
multipart.addBodyPart(messageBodyPart);
forward.setContent(multipart);
Transport.send(forward);
但执行时抛出错误:
javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: IOException while sending message; nested exception is: java.io.IOException: No content
问题出在messageBodyPart.setDataHandler(msg.getDataHandler());
请问各位大虾,如何修改?急!!