Outlook不会将ics显示为邮件中的事件

时间:2019-04-11 08:26:34

标签: email events outlook icalendar

此代码将消息发送到附加了ics存档的Outlook帐户,但是Outlook无法将其识别为事件,也不会在预览中显示。 使用Gmail不会有任何问题。它很好地显示了预览,但是Outlook似乎不兼容。我正在使用ical4j libary版本3.0.6。 有人可以帮我找到问题吗?谢谢

        final String username = "example@gmail.com";
        final String password = "pass";
        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "587");

        try {
            Session session = Session.getInstance(props, new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
            });

            // Define message
            MimeMessage message = new MimeMessage(session);
            message.addHeaderLine("method=REQUEST");
            message.addHeaderLine("charset=UTF-8");
            message.addHeaderLine("component=VEVENT");
            message.addHeaderLine("Content-Type: multipart/alternative");


            MimeMessage mimeMessage = new MimeMessage(session);
            mimeMessage.setHeader("Content-Transfer-Encoding:", "quoted-printable");
            mimeMessage.setHeader("Content-Type:", "multipart/alternative");

            Address address = new InternetAddress("example@gmail.com");
            mimeMessage.setFrom(address);
            message.addRecipients(Message.RecipientType.TO, "example@outlook.es");
            message.setSubject("Outlook Meeting Request Using JavaMail");

            StringBuffer sb = new StringBuffer();

            StringBuffer buffer = sb.append("BEGIN:VCALENDAR\n" +
                    "PRODID:-//Microsoft Corporation//Outlook 9.0 
                     MIMEDIR//EN\n" +
                    "VERSION:2.0\n" +
                    "METHOD:REQUEST\n" +
                    "TZID:Romance Standard Time\n"+
                    /*"BEGIN:STANDARD\n"+
                    "DTSTART:16010101T030000\n"+
                    "TZOFFSETFROM:+0200\n"+
                    "TZOFFSETTO:+0100\n"+
                    "RRULE:FREQ=YEARLY;
                     INTERVAL=1;BYDAY=-1SU;BYMONTH=10\n"+
                    "END:STANDARD\n"+*/
                    "BEGIN:DAYLIGHT\n"+
                    "DTSTART:16010101T020000\n"+
                    "TZOFFSETFROM:+0100\n"+
                    "TZOFFSETTO:+0200\n"+
                    "RRULE:FREQ=YEARLY;
                     INTERVAL=1;BYDAY=-1SU;BYMONTH=3\n"+
                    "END:DAYLIGHT\n"+
                    "BEGIN:VEVENT\n" +
                    "ATTENDEE;EXPECT=REQUIRE;
                     RSVP=YES:MAILTO:example1@outlook.es\n" +
                    "ORGANIZER:MAILTO:example@gmail.com\n" +
                    "DTSTART:20051208T053000Z\n" +
                    "DTEND:20051208T060000Z\n" +
                    "LOCATION:Conference room\n" +
                    "TRANSP:1\n" +
                    "SEQUENCE:0\n" +
                    "LOCATION;LANGUAGE=es-ES:\n"+
                    "X-MICROSOFT-CDO-APPT-SEQUENCE:0\n"+
                    "X-MICROSOFT-CDO-OWNERAPPTID:2117356856\n"+
                    "X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE\n"+
                    "X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\n"+
                    "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE\n"+
                    "X-MICROSOFT-CDO-IMPORTANCE:1\n"+
                    "X-MICROSOFT-CDO-INSTTYPE:0\n"+
                    "X-MICROSOFT-DONOTFORWARDMEETING:FALSE\n"+
                    "X-MICROSOFT-DISALLOW-COUNTER:FALSE\n"+
                    "X-MICROSOFT-LOCATIONS:[]\n"+
                    "UID:040000008200E00074C5B7101A82E008000000000"+
                     02FF466CE3AC5010000000000000000100\n" +
                    " 000004377FE5C37984842BF9440448399EB02\n" +
                    "DTSTAMP:20051206T120102Z\n" +
                    "CATEGORIES:Meeting\n" +
                    "DESCRIPTION:This the description of the meeting\n" +
                    "SUMMARY:Test meeting request\n" +
                    "PRIORITY:5\n" +
                    "CLASS:PUBLIC\n" +
                    "BEGIN:AALARM\n" +
                    "TRIGGER:PT1440M\n" +
                    "ACTION:DISPLAY\n" +
                    "DESCRIPTION:Reminder\n" +
                    "END:AALARM\n" +
                    "END:VEVENT\n" +
                    "END:VCALENDAR");

            // Create the message part
            BodyPart messageBodyPart = new MimeBodyPart();

            // Fill the message
            messageBodyPart.setHeader("
            Content-Class", "urn:content-  classes:calendarmessage");
            messageBodyPart.setHeader("Content-ID", "calendar_message");
            messageBodyPart.setHeader("Content-Type", "inline");
            messageBodyPart.setHeader("filename", "prueba.ics");
            messageBodyPart.setDataHandler(new DataHandler(
                    new ByteArrayDataSource(buffer.toString(), 
            "text/calendar")));// very important

            // Create a Multipart
            Multipart multipart = new MimeMultipart();

            // Add part one
            multipart.addBodyPart(messageBodyPart);

            // Put parts in message
            message.setContent(multipart);

            // send message
            Transport.send(message);
        } catch (MessagingException me) {
            me.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

1 个答案:

答案 0 :(得分:0)

使用:

CONTENT-TYPE:文本/日历;