Django 如何获得会议邀请,以便与Gmail/Google应用程序正确集成?

Django 如何获得会议邀请,以便与Gmail/Google应用程序正确集成?,django,outlook,gmail,icalendar,Django,Outlook,Gmail,Icalendar,我正在使用Django和python iCalendar生成iCalendar文件,它们在Outlook(2010)中正确地显示为会议邀请。在Gmail(谷歌应用程序)中,我只看到一封空白的电子邮件。怎么回事?下面是我的一个.ics文件的外观: BEGIN:VCALENDAR METHOD:REQUEST PRODID:-//My Events App//example.com// VERSION:2.0 BEGIN:VEVENT ATTENDEE;CN=Richard;ROLE=REQ-PAR

我正在使用Django和python iCalendar生成iCalendar文件,它们在Outlook(2010)中正确地显示为会议邀请。在Gmail(谷歌应用程序)中,我只看到一封空白的电子邮件。怎么回事?下面是我的一个.ics文件的外观:

BEGIN:VCALENDAR
METHOD:REQUEST
PRODID:-//My Events App//example.com//
VERSION:2.0
BEGIN:VEVENT
ATTENDEE;CN=Richard;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:rich@example.com
CREATED;VALUE=DATE:20101122T183813
DESCRIPTION:Phone number: (212)-123-4567\n\nThis is a test description
 for the conference call.
DTEND;VALUE=DATE:20101127T131802Z
DTSTAMP;VALUE=DATE:20101127T121802Z
DTSTART;VALUE=DATE:20101127T121802Z
LAST-MODIFIED;VALUE=DATE:20101122T183813
ORGANIZER;CN=Example.com:events@example.com
SEQUENCE:1
SUMMARY:Conference call about GLD
UID:example.com.20
END:VEVENT
END:VCALENDAR
哦,我正在使用Django的EmailMultiAlternations附加ics内容,如下所示:

if calendar:
    message.attach_alternative(calendar.as_string(), "text/calendar; method=REQUEST; charset=\"UTF-8\"")
    message.content_subtype = 'calendar'

很久以前,我不得不处理.ics文件,并开发了一个名为的小助手应用程序,简化了整个过程


它不再处于积极开发阶段,但似乎仍能满足少数人的需求。非常欢迎补丁和改进

这可能有点晚了,但下面是我在模型中作为助手函数的实现(它是一个“事件”模型,包含一个日期作为其自身属性):

然后在发送电子邮件的功能中,我有:

# This one has the plain text version of the message
msg = EmailMultiAlternatives('Event Confirmation', text_email,
                             FROM_EMAIL, [self.user.email])
# This one has the HTML version of the message
msg.attach_alternative(html_email, 'text/html')
# Now to attach the calendar
msg.attach("{0}.ics".format(self.event.slug),
           self.event.generate_calendar(), 'text/calendar')
msg.send(fail_silently=True)
该解决方案使用icalendar(我更喜欢vobject),它还使用attach_alternative()来附加(字面上)消息的替代版本。attach()函数用于放入日历文件,而不管电子邮件客户端选择呈现的消息的版本如何(请注意,我还给了它一个“.ics”扩展名)


我知道您使用的是python icalendar,但是attach()方法应该仍然可以工作。我还决定向您展示生成iCal文件的替代实现。

请参阅相关内容。该解决方案使用“附件”而不是“替代品”,看起来它在google上很有效。@equinoxel但这是因为使用“附件”而不是“替代品”还是使用
vobject
而不是
icalendar
。我真的很喜欢Plone集团开始开发。比起vobject形成的RFC,我一直更喜欢它的API。你的代码非常棒。但是outlook无法将此ics文件识别为日历。缺少什么?@RonaldoBahia您找到解决方案了吗?@ShahriarRahmanZahin Outlook web(hotmail)运行良好。尚未在Outlook桌面上尝试。
# This one has the plain text version of the message
msg = EmailMultiAlternatives('Event Confirmation', text_email,
                             FROM_EMAIL, [self.user.email])
# This one has the HTML version of the message
msg.attach_alternative(html_email, 'text/html')
# Now to attach the calendar
msg.attach("{0}.ics".format(self.event.slug),
           self.event.generate_calendar(), 'text/calendar')
msg.send(fail_silently=True)