如何获得会议邀请以与Gmail/Google Apps正确集成? [英] How can I get a meeting invitation to integrate properly with Gmail/Google Apps?

查看:635
本文介绍了如何获得会议邀请以与Gmail/Google Apps正确集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django和python-icalendar生成iCalendar文件,它们会作为会议邀请正确显示在Outlook(2010)中.在Gmail(Google Apps)中,我只看到一封空白电子邮件.这是怎么回事?这是我的.ics文件之一:

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: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内容,就像这样:

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'

推荐答案

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

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)

该解决方案使用icalendar(我更喜欢vobject),并且还使用attach_alternative()附加(字面意义)该消息的替代版本.不论电子邮件客户端选择呈现的消息版本如何,attach()函数都将被用于扔进日历文件中(请注意,我还给它提供了".ics"扩展名).

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

我意识到您正在使用python-icalendar,但是attach()方法应该仍然可以正常工作.我刚刚决定还向您展示生成iCal文件的另一种实现方式.

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.

这篇关于如何获得会议邀请以与Gmail/Google Apps正确集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆