【问题标题】:How can I get a meeting invitation to integrate properly with Gmail/Google Apps?如何获得会议邀请以与 Gmail/Google Apps 正确集成?
【发布时间】:2010-11-22 23:40:23
【问题描述】:

我正在使用 Django 和 python-icalendar 生成 iCalendar 文件,它们在 Outlook (2010) 中正确显示为会议邀请。在 Gmail (Google Apps) 中,我只看到一封空白电子邮件。这是怎么回事?这是我的一个 .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 的 EmailMultiAlternatives 来附加 ics 内容,如下所示:

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

【问题讨论】:

  • 查看相关post。该解决方案使用“附件”而不是“替代”,看起来它适用于谷歌。
  • @equinoxel 但这是由于使用“附件”而不是“替代”或使用vobject 而不是icalendar。我真的很喜欢 Plone 集体开发 icalendar。我总是更喜欢它的 API,而不是 vobject 形成的 RFC 周围的那个薄层。

标签: django outlook gmail icalendar


【解决方案1】:

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

from icalendar import Calendar, Event as ICalEvent
...
class Event(models.Model):
...
    def generate_calendar(self):
        cal = Calendar()
        site = Site.objects.get_current()

        cal.add('prodid', '-//{0} Events Calendar//{1}//'.format(site.name,
                                                                 site.domain))
        cal.add('version', '2.0')

        ical_event = ICalEvent()
        ical_event.add('summary', self.title)
        ical_event.add('dtstart', self.start_date)
        ical_event.add('dtend', self.end_date)
        ical_event.add('dtstamp', self.end_date)
        ical_event['uid'] = str(self.id)

        cal.add_component(ical_event)
        return cal.to_ical()

然后在发送电子邮件的函数中,我有:

# 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 文件的替代实现。

【讨论】:

  • 您的代码运行良好。但 Outlook 不会将此 ics 文件识别为日历。缺少什么?
  • @RonaldoBahia 你找到解决办法了吗?
  • @ShahriarRahmanZahin Outlook web (hotmail) 工作正常。尚未在 Outlook 桌面上尝试过。
【解决方案2】:

很久以前我不得不使用 .ics 文件,并想出了一个名为 django-cal 的小助手应用程序,它简化了整个过程。

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

【讨论】:

    猜你喜欢
    • 2015-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    • 1970-01-01
    • 2018-10-03
    • 1970-01-01
    • 2016-12-05
    相关资源
    最近更新 更多