1
내 시나리오는 다음과 같습니다.첨부 파일이있는 이메일을 보내는 Java, DataContentHandler의 오류
사용자가 메시지를 작성하고 파일을 첨부하고 이메일을 보냅니다.
나는이 같은 메일을 보낼 JavaMail에를 사용하지만 난 문제 (내 파일이 세션에) 메시지에 파일을 첨부 있습니다
public class MyMailAttachmentDataSource implements DataSource{
private UploadFile file;
public MyMailAttachmentDataSource(UploadFile file){
this.file=file;
}
@Override
public InputStream getInputStream() throws IOException {
return file.getInpuStream();
}
@Override
public OutputStream getOutputStream() throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getContentType() {
return file.getContentType();
}
@Override
public String getName() {
return file.getFileName();
}
}
:
이
if (request.getSession().getAttribute("EMAIL_ATTACHMENT") != null) {
UploadFile file = (UploadFile) request.getSession().getAttribute("EMAIL_ATTACHMENT");
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(text, "text/html;charset=UTF-8");
MimeMultipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
MyMailAttachmentDataSource fds = new MyMailAttachmentDataSource(file);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
mp.addBodyPart(mbp2);
msg.setContent(mp, "text/plain");
}
MyMailAttachmentDataSource에 대한 코드는 다음입니다 내가 이메일을 보내려고하면
, 난는 CH하려고
java.io.IOException: "text/plain" DataContentHandler requires String object, was given object of type class javax.mail.internet.MimeMultipart
at com.sun.mail.handlers.text_plain.writeTo(text_plain.java:97)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:884)
at javax.activation.DataHandler.writeTo(DataHandler.java:317)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1089)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1527)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:321)
at admin.email.JavaMail.SendEmail(JavaMail.java:403)
at admin.email.MailSend.SendMail(MailSend.java:86)
이 예외를 얻을 플랜지 "text/html과"하지만 여전히 얻을 위의 예외에 msg.contentType
"text/html" DataContentHandler requires String object, was given object of type class javax.mail.internet.MimeMultipart
사람이 오류가 발생하고 내가 그것을 어떻게 해결할 수 있는지 알고 있습니까?
얼마나 바보 같은 나를 .... 덕분에 코드 줄을 변경하기에 충분 것으로 보인다 – MaVRoSCy