최근, 아래의 코드 내가 (다른 나를 위해 일한 실제로 아무것도)와 함께 올 수있는 최선입니다 :
이 작업을 처리하는 더 좋은 방법은 아마도있다
public class MultipartGenerator {
//Let's assume the static members below
//hold our message parts content
//an the instances of arrays of byte
private static final byte [] ROOT_BYTES = new byte[]{/* ... bytes ... */};
private static final byte [] ATTCH_1_BYTES = new byte[]{/* ... bytes ... */};
private static final byte [] ATTCH_2_BYTES = new byte[]{/* ... bytes ... */};
/**
* Generate multipart with headers
*
* @return javax.mail.Multipart instance
*/
public static Multipart generateMultipart() {
//This is our root MimeBodyPart,
//content-id equals 'rootcid'
//content-type equals 'roottype/rootsubtype'
InternetHeaders ih0 = new InternetHeaders();
ih0.addHeader("Content-Type", "roottype/rootsubtype");
ih0.addHeader("Content-Transfer-Encoding", "binary");
ih0.addHeader("Content-ID", "rootcid");
MimeBodyPart rootBodyPart = new MimeBodyPart(ih0, ROOT_BYTES);
//This is a body part wrapping first message attachment
InternetHeaders ih1 = new InternetHeaders();
ih1.addHeader("Content-Type", "text/plain; name=attachment1.txt");
ih1.addHeader("Content-Transfer-Encoding", "binary");
ih1.addHeader("Content-Location", "attachment1.txt");
ih1.addHeader("Content-ID", "a00");
MimeBodyPart attch1BodyPart = new MimeBodyPart(ih1, ATTCH_1_BYTES);
//This is a body part wrapping second message attachment
InternetHeaders ih2 = new InternetHeaders();
ih2.addHeader("Content-Type", "text/plain; name=attachment2.txt");
ih2.addHeader("Content-Transfer-Encoding", "binary");
ih2.addHeader("Content-Location", "attachment2.txt");
ih2.addHeader("Content-ID", "a01");
MimeBodyPart attch2BodyPart = new MimeBodyPart(ih2, ATTCH_2_BYTES);
//This is our desired multipart, this is where things turn a bit dirty
//No success with setting the parameters in a different way
Multipart multipart = new MimeMultipart("related;start=\"<rootcid>\";type=\"roottype/rootsubtype\"");
multipart.addBodyPart(rootBodyPart,0);
multipart.addBodyPart(attch1BodyPart);
multipart.addBodyPart(attch2BodyPart);
return multipart;
}
}
, 그러나 나는 그것을 발견 할 수 없다.