使用java电子邮件的日历事件

时间:2016-05-06 12:39:17

标签: java email outlook calendar icalendar

我已经从.ics发送了org.apache.commons.mail.MultiPartEmail个文件,但每个电子邮件服务器上的结果都不同;

示例:

当发送到G-Mail地址时,接收者将.ics文件识别为事件,并在邮件正文中显示事件的详细信息。

在雅虎,它识别事件但不显示详细信息。

在Microsoft邮件服务器(hotmail,outlook)中,.ics文件在邮件正文中显示为明文,但不会被识别为事件。

我真的不知道如何让Microsoft邮件服务器识别该事件并显示详细信息以及要在日历中添加的按钮。

这是.ics代码:

BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
PRODID:LBstation
BEGIN:VEVENT
UID:1e89d5a5-09c3-477c-9dd7-b9af39e514b2
DTSTAMP:20160506T143307Z
SUMMARY:Test ICS
DTSTART:20160529T130000Z
DTEND:20160529T140000Z
ATTENDEE;CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;ROLE=ATTENDEE;CN=Leonardo Outlook:mailto:test@outlook.com
ATTENDEE;CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED;RSVP=TRUE;ROLE=ORGANIZER;CN=Leonardo Peixoto:mailto:test@gmail.com
SEQUENCE:0
ORGANIZER;CN=Leonardo Bruno Peixoto:mailto:test@gmail.com
CREATED:20160506T143307Z
LAST-MODIFIED:20160506T143307Z
DESCRIPTION:Test ics
TRANSP:OPAQUE
STATUS:CONFIRMED
LOCATION:
END:VEVENT
END:VCALENDAR

这是代码:

MimeMultipart mmp = new MimeMultipart("mixed");

    MimeMultipart mmpa = new MimeMultipart("alternative");

    MimeBodyPart plainPart = new MimeBodyPart();
    plainPart.setHeader("Content-Type", "text/plain; charset=UTF-8; format=flowed; delsp=yes");
    plainPart.setHeader("Content-Transfer-Encoding", "base64");
    ByteArrayDataSource dsPlain = new ByteArrayDataSource("","text/plain;method=REQUEST");
    DataHandler dhPlain = new DataHandler(dsPlain);
    plainPart.setDataHandler(dhPlain);
    mmpa.addBodyPart(plainPart);

    MimeBodyPart calendarPart = new MimeBodyPart();
    calendarPart.setHeader("Content-Type", "text/calendar; charset=UTF-8; method=REQUEST");
    calendarPart.setHeader("Content-Transfer-Encoding", "7bit");
    ByteArrayDataSource dsCalendario = new ByteArrayDataSource(str,"text/calendar;method=REQUEST");
    DataHandler dhCalendario = new DataHandler(dsCalendario);
    calendarPart.setDataHandler(dhCalendario);
    mmpa.addBodyPart(calendarPart);

    MimeBodyPart htmlAndTextBodyPart = new MimeBodyPart();
    htmlAndTextBodyPart.setContent(mmpa);
    mmp.addBodyPart(htmlAndTextBodyPart);


    email.addPart(mmp);

1 个答案:

答案 0 :(得分:0)

解决了! 问题是,当SimpleEmail完美地工作时,为MultiPartEmail创建了mimepart。

<?php echo form_open_multipart('welcome/staff_bulk_upload_process', ['role' => 'form']); ?>
    <fieldset>
        <div class="col-sm-offset-2 hidden">
            <img src="<?php echo base_url("assets/images/ajax-loader.gif"); ?>">
        </div>
        <br/>
        <div class="form-group">
           <label class="sr-only" for="staff_file">Import Staff Data</label>
           <input type="file" class="form-control" id="staff_file" name="staff_file" />
        </div>
        <div class="form-group">    
            <button type="submit" class="btn btn-default btn-block" id="importStaff">Upload File</button>
        </div>
    </fieldset>
<?php echo form_close(); ?>