我正在动态地在我的java代码中创建icalender邀请。现在,我想将此icalender邀请作为附件发送到邮件中,而不将其作为文件保存到我的服务器。
我怎样才能实现它?
我的代码是:
public static void sendNow(String subject, String[] toArray, String[] ccArray, BodyPart bodyPart, BodyPart headerPart, List <MimeMessage> attachments ) {
MimeMessage message = new MimeMessage(getMimeSession());
// Add From Email id
// Add TO receipients
// Add CC receipients
// SET Subject
// Create a Multipart
Multipart multipart = new MimeMultipart();
if (null != bodyPart) {
multipart.addBodyPart(bodyPart);
}
if (null != headerPart) {
multipart.addBodyPart(headerPart);
}
// Attaching MIMEMessage as attachment - IT IS NOT WORKING
if(null != attachments) {
//attach meeting invitation
for (MimeMessage attach : attachments) {
message.setDataHandler(attach.getDataHandler());
message.setFileName(attach.getSubject() + ".ics");
}
}
// Put parts in message
message.setContent(multipart);
// SEND
}