我想使用 java 在 Outlook 日历邀请中附加多个文件
我想使用 java 在日历邀请中附加多个文件。 目前,我可以使用 html 正文创建邀请,但无法向该邀请添加附件。
有谁知道如何附加文件。
我不会将邀请作为附件发送。它按照正常的接受/拒绝方式进行。
请尽快发布。 提前致谢
代码如下:
MimetypesFileTypeMap mimetypes = (MimetypesFileTypeMap) MimetypesFileTypeMap.getDefaultFileTypeMap();
mimetypes.addMimeTypes("text/calendar ics ICS");
MailcapCommandMap mailcap = (MailcapCommandMap) MailcapCommandMap.getDefaultCommandMap();
mailcap.addMailcap("text/calendar;; x-java-content-handler=com.sun.mail.handlers.text_plain");
Properties props = new Properties();
props.setProperty("mail.transport.protocol", " ");
props.setProperty("mail.host", mailServer);
//props.setProperty("mail.user", "emailuser");
//props.setProperty("mail.password", "");
Session mailSession = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(mailSession);
//message.addHeaderLine("text/calendar;method=REQUEST;charset=UTF-8");
/* String emailAddress = invite_email;
String fullName = invite_name;*/
String emailAddress = "[email protected]";
String fullName = "ABCD";
message.setFrom(new InternetAddress(replyEmail, replyEmailName));
javax.mail.Address address = new InternetAddress(emailAddress, fullName);
message.addRecipient(MimeMessage.RecipientType.TO, address);
message.setSubject("abc" + invite_sub);
// Create a Multipart
Multipart multipart = new MimeMultipart("alternative");
//part 1, html text
BodyPart messageBodyPart = buildHtmlTextPart(team_id);
multipart.addBodyPart(messageBodyPart);
// Add part two, the calendar
BodyPart calendarPart = buildCalendarPartNew(emailAddress , fullName , invite_sub , invite_uuid ,start_date , finish_date , invite_seq , invite_status , invite_timezone );
multipart.addBodyPart(calendarPart);
// Add attachments to the body
multipart = addAttachment(multipart,Req_List);
//update the requisition id list back to " " once the attachment process is over
Req_List = " ";
// Put parts in message
System.out.println("setting the content of message");
message.setContent(multipart);
// send message
try {
Transport transport = mailSession.getTransport();
transport.connect();
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
transport.close();
}
catch (Exception ex) {
System.out.println(ex.toString());
throw ex;
}
附件的功能主要包含:
FileDataSource fds1 = new FileDataSource(sharepath_name);
attachment.setDataHandler(new DataHandler(fds1));
attachment.setFileName(fds1.getName());
attachment.setHeader("MIME-Version", "1.0");
attachment.setHeader("Content-Type", " "+mime_type+ "; name=\"" + sharepath_name + "\"");
attachment.setHeader("Content-Disposition", "attachment; filename=\"" + sharepath_name + "\"");
attachment.setHeader("Content-Transfer-Encoding", "base64");
multipart.addBodyPart(attachment);
return multipart;
没有错误,邀请是用文本生成的,但主要问题是我想要邀请中的附件,我无法在其中附加文件邀请,我不知道如何在邀请中附加文件? 另外,我需要在邀请中提供多个附件。
提前致谢
I want to attach multiple files inside a calendar invite using java.
Currently i am able to create an invite with the html body text but i am not able to add attachments to that invite.
Does anyone knows how to attach files.
I am not sending the invite as attachment. It is going as normal accept/decline way.
Please post ASAP .
Thanks in advance
CODE AS FOLLOWS :
MimetypesFileTypeMap mimetypes = (MimetypesFileTypeMap) MimetypesFileTypeMap.getDefaultFileTypeMap();
mimetypes.addMimeTypes("text/calendar ics ICS");
MailcapCommandMap mailcap = (MailcapCommandMap) MailcapCommandMap.getDefaultCommandMap();
mailcap.addMailcap("text/calendar;; x-java-content-handler=com.sun.mail.handlers.text_plain");
Properties props = new Properties();
props.setProperty("mail.transport.protocol", " ");
props.setProperty("mail.host", mailServer);
//props.setProperty("mail.user", "emailuser");
//props.setProperty("mail.password", "");
Session mailSession = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(mailSession);
//message.addHeaderLine("text/calendar;method=REQUEST;charset=UTF-8");
/* String emailAddress = invite_email;
String fullName = invite_name;*/
String emailAddress = "[email protected]";
String fullName = "ABCD";
message.setFrom(new InternetAddress(replyEmail, replyEmailName));
javax.mail.Address address = new InternetAddress(emailAddress, fullName);
message.addRecipient(MimeMessage.RecipientType.TO, address);
message.setSubject("abc" + invite_sub);
// Create a Multipart
Multipart multipart = new MimeMultipart("alternative");
//part 1, html text
BodyPart messageBodyPart = buildHtmlTextPart(team_id);
multipart.addBodyPart(messageBodyPart);
// Add part two, the calendar
BodyPart calendarPart = buildCalendarPartNew(emailAddress , fullName , invite_sub , invite_uuid ,start_date , finish_date , invite_seq , invite_status , invite_timezone );
multipart.addBodyPart(calendarPart);
// Add attachments to the body
multipart = addAttachment(multipart,Req_List);
//update the requisition id list back to " " once the attachment process is over
Req_List = " ";
// Put parts in message
System.out.println("setting the content of message");
message.setContent(multipart);
// send message
try {
Transport transport = mailSession.getTransport();
transport.connect();
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
transport.close();
}
catch (Exception ex) {
System.out.println(ex.toString());
throw ex;
}
THE FUNCTION FOR ATTACHMENT MAINLY CONTAINS :
FileDataSource fds1 = new FileDataSource(sharepath_name);
attachment.setDataHandler(new DataHandler(fds1));
attachment.setFileName(fds1.getName());
attachment.setHeader("MIME-Version", "1.0");
attachment.setHeader("Content-Type", " "+mime_type+ "; name=\"" + sharepath_name + "\"");
attachment.setHeader("Content-Disposition", "attachment; filename=\"" + sharepath_name + "\"");
attachment.setHeader("Content-Transfer-Encoding", "base64");
multipart.addBodyPart(attachment);
return multipart;
there is no error as such , the invite is getting generated with the text , but the main problem is i want attachments inside the invite, i am not able to attach files inside the invite, i don't know how to attach files inside invite ?
Also the attachments i need to provide multiple attachments inside the invite.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过不手动设置附件标题?它们应该由 MimeMessage 设置。
Have you tried without setting the attachment headers manually? They should be set by MimeMessage.