gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:38:29 24 4
gpt4 key购买 nike

我已经制作了一个 .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);

最佳答案

解决了!问题是,为 MultiPartEmail 创建 mimepart 放入 SimpleEmail 时效果很好。

SimpleEmail email = new SimpleEmail();

MimeMultipart mmpa = new MimeMultipart("alternative");

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

email.setContent(mmpa);

关于java - 使用 java 电子邮件的日历事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37072652/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com