发送到Outlook的ICS文件不会作为事件进行调整
我需要开发一个应用程序,以将事件发送到Gmail / Outlook日历。使用Java Mail 1.5.5。我对1.6.2版进行了一些测试,没有更多成功 所选的解决方案是生成ICS文件,并通过电子邮件将其发送到目标日历地址。
在Gmail上,该电子邮件被广泛认可为事件电子邮件(该电子邮件包含事件的描述,更改答案的可能性,并自动将事件添加到日历中),
在Outlook上,附件未被视为事件(该电子邮件仅包含ICS文件作为附件,没有描述或响应请求,并且事件不会自动添加到日历中)。然后,您必须单击附件,然后在“添加到日历”上,以便在日历中创建事件,
我在网上找到了许多类似的主题,但是没有帮助我解决问题的问题,
问题可能来自ICS文件或邮件的标题。 ICS文件对我来说看起来不错:如果在Gmail上,我创建了一条新消息,我将ICS添加为附件,然后将其发送到我的Outlook地址,该电子邮件被很好地识别为事件,
这是ICS的内容文件
BEGIN:VCALENDAR
PRODID:<MYPRODID>
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTAMP:20220629T121224Z
SUMMARY:Test Event
DTSTART:20220630T110000Z
DTEND:20220630T130000Z
UID:<MYUID>
SEQUENCE:1656460800
DESCRIPTION:Event body
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=FALSE;CN=<MYCN>:mailto:<MYEMAIL>
ORGANIZER;CN=<MYORGNAME>:mailto:<MYORGEMAIL>
END:VEVENT
END:VCALENDAR
我对标题 /邮件结构有一些疑问。我在互联网上找到了很多不同的内容,但是我尝试的一切都会导致相同的结果(需要在Outlook中打开电子邮件,手动导入附件),
这是我的Java代码:在上次测试中:
Properties prop = new Properties();
prop.put("mail.mime.charset", "UTF-8");
prop.put("mail.smtp.host", "<MYHOST>");
prop.put("mail.smtp.port", "<MYPORT>");
prop.put("mail.smtp.auth", Boolean.TRUE.toString());
prop.put("mail.smtp.user", "<MYUSER>");
prop.put("password", "<MYPASS>");
String from = "<MYORGEMAIL>";
String to = "<MYEMAIL>";
Session session = Session.getInstance(prop, new SMTPAuthenticator(prop));
// Define message
MimeMessage message = new MimeMessage(session);
message.addHeader("method", "REQUEST");
message.addHeader("charset", "UTF-8");
message.addHeader("component", "VEVENT");
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Outlook Meeting Request Using JavaMail");
File invitation = new File("<MYFILEPATH>\\vCalendar_5067936453064913847.ics");
MimeMultipart mixed = new MimeMultipart("mixed");
// Create the message part
MimeMultipart alternative = new MimeMultipart("alternative");
MimeBodyPart alternativePart = new MimeBodyPart();
alternativePart.setContent(alternative);
mixed.addBodyPart(alternativePart);
MimeBodyPart plain = new MimeBodyPart();
plain.setText("body", "UTF-8", "plain");
MimeBodyPart html = new MimeBodyPart();
html.setText("<div dir=\"ltr\">body</div>", "UTF-8", "html");
alternative.addBodyPart(plain);
alternative.addBodyPart(html);
// Create the attachment part
BodyPart icsBodyPart = new MimeBodyPart();
icsBodyPart.addHeader("method", "REQUEST");
icsBodyPart.addHeader("Content-Class", "urn:content-classes:calendarmessage");
icsBodyPart.addHeader("Content-ID", "calendar_message");
icsBodyPart.addHeader("component", "VEVENT");
FileInputStream inputStream = new FileInputStream(invitation.getAbsolutePath());
final DataSource source =
new ByteArrayDataSource(inputStream,
"text/calendar; charset=\"UTF-8\"; name=\"vCalendar_5067936453064913847.ics\"");
icsBodyPart.setDataHandler(new DataHandler(source));
icsBodyPart.setFileName(invitation.getName());
mixed.addBodyPart(icsBodyPart);
// Put parts in message
message.setContent(mixed);
// send message
Transport.send(message);
知道如何构建我的哑光零件,我在Gmail Sendbox(由Outlook进行调整的零件)中查看我的消息结构:
MIME-Version: 1.0
Date: Tue, 12 Jul 2022 14:44:10 +0200
Message-ID: <[email protected]>
Subject: Mail title test
From: XXXXXXXXXXX <[email protected]>
To: XXXXXXXXXXX <[email protected]>
Content-Type: multipart/mixed; boundary="00000000000072927505e39b0616"
--00000000000072927505e39b0616
Content-Type: multipart/alternative; boundary="00000000000072927005e39b0614"
--00000000000072927005e39b0614
Content-Type: text/plain; charset="UTF-8"
Mail content test
--00000000000072927005e39b0614
Content-Type: text/html; charset="UTF-8"
<div dir="ltr">Mail content test<br></div>
--00000000000072927005e39b0614--
--00000000000072927505e39b0616
Content-Type: text/calendar; charset="UTF-8"; name="vCalendar_5067936453064913847.ics"
Content-Disposition: attachment; filename="vCalendar_5067936453064913847.ics"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_l4i5zybk0
Content-ID: <f_l4i5zybk0>
QkVHSU46VkNBTEVOREFSClBST0RJRDpTeWxvYiBudWxsClZFUlNJT046Mi4wCkNBTFNDQUxFOkdS
RUdPUklBTgpXXXXXXXXXXXVRVUVTVApCRUdJTjpWRVZFTlQKRFRTVEFNUDoyMDIyMDYyOVQxMjEy
MjRaClNVTU1BUlk6NSAtIMOJdsOpbmVtZW50IGR1IDI4MDYgw6AgU3lsb2IgZGUgZMOpbW8gCkRU
U1RBUlQ6MjAyMjA2MzBUMTEwMDAwWgpEVEVORDoyMDIyMDYzMFQxMzAwMDBaClVJRDp0ZXN0VWlk
MTY1OTc1QHN5bG9iLmNvbQpTRVFVRU5DRToxNjU2NDYwODAwCkRFU0NSSVBUSU9OOlRlc3QgZGUg
Y29ycCBkZSB0ZXh0ZVxuc3VyIHBsdXNpZXVycyBsaWduZXNcLCBhY2NlbnRzIMOgIHRlc3RlcgpB
VFRFTkRFRTtST0xFPVJFUSXXXXXXXXXXXXXOVDtQQVJUU1RBVD1BQ0NFUFRFRDtSU1ZQPUZBTFNF
O0NOPUFsZXhhbmRyZSBORURORUQ6bWFpbHRvOmFsZXgubmVkamFyaUBnbWFpbC5jb20KT1JHQU5J
WkVSO0NOPSJPcmfDom5pc2F0ZXVyIjptYWlsdG86ZGF0YUBzeWxvYi5jb20KRU5EOlZFVkVOVApF
TkQ6VkNBTEVOREFSCgo=
--00000000000072927505e39b0616--
如果我知道如何在Outlook上查看相同的信息,我可以比较从Gmail收到的邮件,以及从Gmail收到的邮件以及从Java,但我不确定是否可能(我找到了“显示 /消息详细信息”选项,但是此选项仅显示有关顶级MIME部分的信息,而不是完整的Mime结构)
是否有人知道如何解决此问题问题?
谢谢,
I need to develop an application to send events to Gmail / Outlook calendars. Java mail 1.5.5 is used. I did some tests with version 1.6.2, without more success
The chosen solution is to generate ics files, and send them by email to the target calendars adresses.
On Gmail, the email is well recognized as an event email (the email contains the description of the event, the possibility to change the answer, and the event is automatically added to the calendar)
On Outlook, the attachment is not recognized as an event (the email just contains the ics file as an attachment, no description or response request, and the event is not automatically added to the calendar) . You must then click on the attachment, then on "Add to calendar" so that the event is created in the calendar
I found many similar topics on the net, but nothing that helped me solve the problem
The problem could come from the ics file or the headers of the mail. The ics file looks good to me: If on gmail, I create a new message, I add my ics as an attachment, and I send it to my Outlook address, the email is well recognized as an event
Here is the content of the ics file
BEGIN:VCALENDAR
PRODID:<MYPRODID>
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTAMP:20220629T121224Z
SUMMARY:Test Event
DTSTART:20220630T110000Z
DTEND:20220630T130000Z
UID:<MYUID>
SEQUENCE:1656460800
DESCRIPTION:Event body
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=FALSE;CN=<MYCN>:mailto:<MYEMAIL>
ORGANIZER;CN=<MYORGNAME>:mailto:<MYORGEMAIL>
END:VEVENT
END:VCALENDAR
I have some doubt on the headers / mail structure. I find a lot of different things on the internet, but everything I try leads to the same result (the need to open my email in Outlook, to manually import the attachment)
Here is my java code during the last tests:
Properties prop = new Properties();
prop.put("mail.mime.charset", "UTF-8");
prop.put("mail.smtp.host", "<MYHOST>");
prop.put("mail.smtp.port", "<MYPORT>");
prop.put("mail.smtp.auth", Boolean.TRUE.toString());
prop.put("mail.smtp.user", "<MYUSER>");
prop.put("password", "<MYPASS>");
String from = "<MYORGEMAIL>";
String to = "<MYEMAIL>";
Session session = Session.getInstance(prop, new SMTPAuthenticator(prop));
// Define message
MimeMessage message = new MimeMessage(session);
message.addHeader("method", "REQUEST");
message.addHeader("charset", "UTF-8");
message.addHeader("component", "VEVENT");
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Outlook Meeting Request Using JavaMail");
File invitation = new File("<MYFILEPATH>\\vCalendar_5067936453064913847.ics");
MimeMultipart mixed = new MimeMultipart("mixed");
// Create the message part
MimeMultipart alternative = new MimeMultipart("alternative");
MimeBodyPart alternativePart = new MimeBodyPart();
alternativePart.setContent(alternative);
mixed.addBodyPart(alternativePart);
MimeBodyPart plain = new MimeBodyPart();
plain.setText("body", "UTF-8", "plain");
MimeBodyPart html = new MimeBodyPart();
html.setText("<div dir=\"ltr\">body</div>", "UTF-8", "html");
alternative.addBodyPart(plain);
alternative.addBodyPart(html);
// Create the attachment part
BodyPart icsBodyPart = new MimeBodyPart();
icsBodyPart.addHeader("method", "REQUEST");
icsBodyPart.addHeader("Content-Class", "urn:content-classes:calendarmessage");
icsBodyPart.addHeader("Content-ID", "calendar_message");
icsBodyPart.addHeader("component", "VEVENT");
FileInputStream inputStream = new FileInputStream(invitation.getAbsolutePath());
final DataSource source =
new ByteArrayDataSource(inputStream,
"text/calendar; charset=\"UTF-8\"; name=\"vCalendar_5067936453064913847.ics\"");
icsBodyPart.setDataHandler(new DataHandler(source));
icsBodyPart.setFileName(invitation.getName());
mixed.addBodyPart(icsBodyPart);
// Put parts in message
message.setContent(mixed);
// send message
Transport.send(message);
To know how to structure my mime parts, I look to my message structure in my gmail sendbox (the one that is reconized by Outlook) :
MIME-Version: 1.0
Date: Tue, 12 Jul 2022 14:44:10 +0200
Message-ID: <[email protected]>
Subject: Mail title test
From: XXXXXXXXXXX <[email protected]>
To: XXXXXXXXXXX <[email protected]>
Content-Type: multipart/mixed; boundary="00000000000072927505e39b0616"
--00000000000072927505e39b0616
Content-Type: multipart/alternative; boundary="00000000000072927005e39b0614"
--00000000000072927005e39b0614
Content-Type: text/plain; charset="UTF-8"
Mail content test
--00000000000072927005e39b0614
Content-Type: text/html; charset="UTF-8"
<div dir="ltr">Mail content test<br></div>
--00000000000072927005e39b0614--
--00000000000072927505e39b0616
Content-Type: text/calendar; charset="UTF-8"; name="vCalendar_5067936453064913847.ics"
Content-Disposition: attachment; filename="vCalendar_5067936453064913847.ics"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_l4i5zybk0
Content-ID: <f_l4i5zybk0>
QkVHSU46VkNBTEVOREFSClBST0RJRDpTeWxvYiBudWxsClZFUlNJT046Mi4wCkNBTFNDQUxFOkdS
RUdPUklBTgpXXXXXXXXXXXVRVUVTVApCRUdJTjpWRVZFTlQKRFRTVEFNUDoyMDIyMDYyOVQxMjEy
MjRaClNVTU1BUlk6NSAtIMOJdsOpbmVtZW50IGR1IDI4MDYgw6AgU3lsb2IgZGUgZMOpbW8gCkRU
U1RBUlQ6MjAyMjA2MzBUMTEwMDAwWgpEVEVORDoyMDIyMDYzMFQxMzAwMDBaClVJRDp0ZXN0VWlk
MTY1OTc1QHN5bG9iLmNvbQpTRVFVRU5DRToxNjU2NDYwODAwCkRFU0NSSVBUSU9OOlRlc3QgZGUg
Y29ycCBkZSB0ZXh0ZVxuc3VyIHBsdXNpZXVycyBsaWduZXNcLCBhY2NlbnRzIMOgIHRlc3RlcgpB
VFRFTkRFRTtST0xFPVJFUSXXXXXXXXXXXXXOVDtQQVJUU1RBVD1BQ0NFUFRFRDtSU1ZQPUZBTFNF
O0NOPUFsZXhhbmRyZSBORURORUQ6bWFpbHRvOmFsZXgubmVkamFyaUBnbWFpbC5jb20KT1JHQU5J
WkVSO0NOPSJPcmfDom5pc2F0ZXVyIjptYWlsdG86ZGF0YUBzeWxvYi5jb20KRU5EOlZFVkVOVApF
TkQ6VkNBTEVOREFSCgo=
--00000000000072927505e39b0616--
If I knew how to see the same informations on outlook, I could compare the mail received from gmail and the one received from java, but I'm not sure it's possible (I found the "display / message details" option, but this option only show informations about the top level mime part, not the complete mime structure)
Does anyone have an idea how to fix this problem?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也有类似的问题,并在重写
content-type
标题方面找到了解决方案。我已经在此标题中添加了method = request
,然后在Outlook开始将我的电子邮件识别为事件之后。Python上的代码示例:
I had a similar problem and found a solution in rewriting a
Content-Type
header. I've addedmethod=REQUEST
to this header and after that outlook started recognize my emails as events.Example of code on python:
对于您在EML文件中的ICS部分,添加
请求
语句是必要的。对于您的EML文件,可能看起来像:
请求
可以是发布
,请求
,回复
,添加
,取消
,刷新
或counter
counter以及您的Java代码,更改
为
For your ics part in eml file,adding a
request
statement is necessary.For your eml file,it may look like:
The
request
can bePUBLISH
,REQUEST
,REPLY
,ADD
,CANCEL
,REFRESH
orCOUNTER
And for your Java code,change
to