1

I use send_raw_email to send emails with HTML content and file attachments. How do I insert an ical/ics invite to the email?

I use icalendar to generate ics content.

This is what I came up with so far, but it shows in Gmail as a file attachment.

    if calendar_reminder_date:
        cal = Calendar()
        cal.add('prodid', '-//My calendar product//mxm.dk//')
        cal.add('version', '2.0')
        cal.add('calscale', 'GREGORIAN')
        cal.add('method', 'REQUEST')
        event = Event()
        event['dtstart'] = calendar_reminder_date.strftime("%Y%m%dT%H%M%SZ")
        event['dtstamp'] = calendar_reminder_date.strftime("%Y%m%dT%H%M%SZ")
        event['summary'] = 'Python meeting about calendaring'
        cal.add_component(event)

        attachment_part = MIMEText(cal.to_ical())
        print repr(cal.to_ical())
        del attachment_part['Content-Type']
        attachment_part.add_header('Content-Type', 'text/calendar', name='invite.ics')
        attachment_part.add_header('Content-Disposition', 'attachment', filename='invite.ics')
        msg.attach(attachment_part)
Jesvin Jose
  • 22,498
  • 32
  • 109
  • 202

1 Answers1

0

Hard to tell without seeing the actual full MIME message as received on the Google side but there are definitely several things missing here:

  • a calendar REQUEST must have an ORGANIZER property, as well as at least one ATTENDEE property with a value corresponding to the email address of the gmail user (prefixed with a mailto:).
  • your content-type is missing a METHOD=REQUEST parameter and you probably do not want to set any content-disposition.

See also Multipart email with text and calendar: Outlook doesn't recognize ics

Community
  • 1
  • 1
Arnaud Quillaud
  • 4,420
  • 1
  • 12
  • 8
  • Could you please have a look at [my question](https://stackoverflow.com/questions/63733904/cannot-see-event-title-in-the-email-invitation-on-microsoft-outlook)? – a_sid Sep 04 '20 at 16:57