事件电子邮件作为附件收到,而不是作为添加到日历的请求

时间:2014-03-07 08:55:10

标签: java html-email email-attachments

这是我的发送邮件功能。用于将邮件发送到电子邮件地址的邮件包含一个事件,可以通过单击电子邮件中的“是”按钮将其添加到客户日历中。

 public static void main(String[] args) throws IOException, ValidationException {
            List<String> to= new ArrayList<String>();
            String subject="";
            StringBuffer sb = new StringBuffer();
            StringBuffer buffer = sb.append("BEGIN:VCALENDAR\n" +
                    "PRODID:Zimbra-Calendar-Provider\n" +
                    "VERSION:2.0\n" +
                    "METHOD:REQUEST\n" +
                    "BEGIN:VTIMEZONE\n" +
                    "TZID:Asia/Kolkata\n" +
                    "BEGIN:STANDARD\n" +
                    "DTSTART:16010101T000000\n" +
                    "TZOFFSETTO:+0530\n" +
                    "TZOFFSETFROM:+0530\n" +
                    "TZNAME:IST\n" +
                    "END:STANDARD\n" +
                    "END:VTIMEZONE\n" +
                    "BEGIN:VEVENT\n" +
                    "UID:06d8d851-e665-4930-a18c-3d60dbaed6e4\n" +
                    "SUMMARY:Test\n" +
                    "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:mailto:mailto"+
                    " @ac.us\n" +
                    "ORGANIZER;CN=Vinay Kumar:mailto:orgnizar@ej.com\n" +
                    "DTSTART;TZID='Asia/Kolkata':20140306T120000\n" +
                    "DTEND;TZID='Asia/Kolkata':20140306T130000\n" +
                    "STATUS:CONFIRMED\n" +
                    "CLASS:PUBLIC\n" +
                    "X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\n" +
                    "TRANSP:OPAQUE\n" +
                    "LAST-MODIFIED:20140306T123110Z\n" +
                    "DTSTAMP:20140306T123110Z\n" +
                    "SEQUENCE:0\n" +
                    "DESCRIPTION:The following is a new meeting request:\n\nSubject: Test \nOrgan"+
                    " izer: orgnizar <orgnizar@ej.com> \n\nTime: Thursday'\', March 6'\',"+
                    "  2014'\', 12:00:00 PM - 1:00:00 PM GMT +05:30 Chennai'\', Kolkata'\', Mumbai'\', New"+
                    "  Delhi\n \nInvitees: dg@ac.us \n\n\n*~*~*~*~*~*~*~*~*~*\n\nTest\n" +
                    "BEGIN:VALARM\n" +
                    "ACTION:DISPLAY\n" +
                    "TRIGGER;RELATED=START:-PT5M\n" +
                    "DESCRIPTION:Reminder\n" +
                    "END:VALARM\n" +
                    "END:VEVENT\n" +
                    "END:VCALENDAR);\n");
    Session session = Session.getDefaultInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(
                                userName, password);
                    }
                });
        session.setDebug(sessionDebug);
        try {

                Multipart multiPart = new MimeMultipart("alternative");
                Message msg = new MimeMessage(session);
                msg.addHeader("method","REQUEST");
                msg.addHeader("component","VEVENT");
                msg.setFrom(new InternetAddress("orgnizar@ej.com"));//emailConfig.getFromEmail()));
                msg.setReplyTo(new javax.mail.Address[] { new javax.mail.internet.InternetAddress("vj@ej.com")});//emailConfig.getReplyTo()) });
                msg.setSubject("Outlook Meeting Request Using JavaMail");
                boolean first=true;
                String result="";
                    msg.addRecipients(Message.RecipientType.TO, address);
                    msg.setSentDate(new Date());
                BodyPart messageBodyPart = new MimeBodyPart();

                    // Fill the message 
                    messageBodyPart.addHeader("Content-Transfer-Encoding", "7bit");
    //              messageBodyPart.addHeader("Content-ID","calendar_message");
                    messageBodyPart.addHeader("Content-Type","text/calendar");
                    messageBodyPart.addHeader("charset","UTF-8");
                    messageBodyPart.addHeader("method","REQUEST");
                    messageBodyPart.setFileName("sss.ics");
                    messageBodyPart.setDataHandler(new DataHandler(
                    new ByteArrayDataSource(buffer.toString(), "text/calendar")));//very important
                    multiPart.addBodyPart(messageBodyPart);

                    msg.setContent(multiPart);

                    /*DataSource ds = new ByteArrayDataSource(buffer.toString(), "application/x-any");
                    msg.setDataHandler(new DataHandler(ds));*/
                    Transport.send(msg);
                    Thread.sleep(5000);
                }

        } catch (MessagingException mex) {

        } catch (InterruptedException e) {

        }
        finally{
            session=null;
        }

目前,我收到的电子邮件中附有.ics个文件作为附件,我需要将其作为一个事件,可以通过点击“是”直接添加到日历中。

0 个答案:

没有答案