简体   繁体   English

我想使用Java在Outlook日历邀请中附加多个文件

[英]I want to attach multiple files in outlook calendar invite using java

I want to attach multiple files inside a calendar invite using java. 我想使用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. 目前,我可以使用html正文创建邀请,但无法向该邀请添加附件。

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 = "XYZ@aBC.com";
    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 提前致谢

Have you tried without setting the attachment headers manually? 您是否尝试过不手动设置附件标题? They should be set by MimeMessage. 它们应该由MimeMessage设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM