轉發郵件附件丟了

YEJIANHUI423發表於2004-07-06
public class ForwardAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
DynaActionForm m = (DynaActionForm) form;
String to = (String) m.get("to");

HttpSession session = request.getSession(false);
if (session == null) {
throw new SessionTimeOutException();
}
Message message = (Message) session.getAttribute(Constant.SESSION_MESSAGE_KEY);
User user = (User) session.getAttribute(Constant.SESSION_USER_KEY);
MaildirStore store = (MaildirStore) user.getStore();
MimeMessage forward = new MimeMessage(store.getSession());
forward.setSubject("Fwd: " + message.getSubject(),"UTF-8");
forward.setFrom(new InternetAddress(user.getEmail()));
forward.setSentDate(new Date());
forward.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
BodyPart mbp1 = new MimeBodyPart();
mbp1.setText("Here you go with the original message:\n\n"+message.getBody());
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mbp1);
BodyPart mbp2 = new MimeBodyPart();
mbp2.setDataHandler(message.getMessage().getDataHandler());
multipart.addBodyPart(mbp2);
forward.setContent(multipart);
Transport.send(forward);
return mapping.findForward("Success");
}
}

相關文章