如何获得会议邀请以与 Gmail/Google Apps 正确集成?

发布于 2024-10-03 20:17:55 字数 1239 浏览 5 评论 0原文

我正在使用 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:[email protected]
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:[email protected]
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'

I am generating iCalendar files with Django and python-icalendar, and they correctly show up in Outlook (2010) as meeting invitations. In Gmail (Google Apps), I just see a blank email. What's the deal? Here's what one of my .ics files looks like:

BEGIN:VCALENDAR
METHOD:REQUEST
PRODID:-//My Events App//example.com//
VERSION:2.0
BEGIN:VEVENT
ATTENDEE;CN=Richard;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:[email protected]
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:[email protected]
SEQUENCE:1
SUMMARY:Conference call about GLD
UID:example.com.20
END:VEVENT
END:VCALENDAR

Oh, and I'm using Django's EmailMultiAlternatives to attach the ics content, like so:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

所谓喜欢 2024-10-10 20:17:55

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

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

This may be a little late, but here is my implementation as a helper function in my model (it's an "event" model that contains a date as a property of itself):

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()

And then in the function that sends the email, I have:

# 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)

That solution uses icalendar (which I prefer to vobject), and it also uses attach_alternative() to attach (literally) an alternative version of the message. The attach() function is being used to toss in the calendar file, regardless of the version of the message that the email client chooses to render (note that I also gave it an ".ics" extension).

I realize that you are using python-icalendar, but the attach() method should still work about the same. I just decided to also show you an alternative implementation to generating iCal files.

-残月青衣踏尘吟 2024-10-10 20:17:55

很久以前,我不得不尝试使用 .ics 文件,并想出了一个名为 django-cal< /a>,这简化了整个过程。

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

I had to play around with .ics files ages ago, and came up with a little helper app named django-cal, which simplifies the whole process.

It's not in active development anymore, but seems to still satisfy the need of a few people. Patches and improvements very welcome!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文