开发者

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

开发者 https://www.devze.com 2023-03-06 14:25 出处:网络
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.

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 = "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.

0

精彩评论

暂无评论...
验证码 换一张
取 消