Skip to content

Instantly share code, notes, and snippets.

@SAPikachu
Created July 20, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SAPikachu/caa7da4925d1872d95db to your computer and use it in GitHub Desktop.
Save SAPikachu/caa7da4925d1872d95db to your computer and use it in GitHub Desktop.
Test code for sending mail to change event in Google Calendar
#!/usr/bin/env python3
import requests
# sapikachu@gmail.com is the organizer, calendar@sapikachu.net is controlled by our app and wants to update the event
# Message body is modified from the mail sent by Google Calendar
body = """Date: Fri, 17 Jul 2015 13:23:53 +0000
Subject: Updated: RFC2446 Test @ Tue Jul 21, 2015 5pm - 6pm (i@sapikachu.net)
From: calendar@sapikachu.net
To: Joe Hu <sapikachu@gmail.com>, i@sapikachu.net
Content-Type: multipart/mixed; boundary=047d7bf0e8e4de0bd8051b121546
--047d7bf0e8e4de0bd8051b121546
Content-Type: multipart/alternative; boundary=047d7bf0e8e4de0bc9051b121544
--047d7bf0e8e4de0bc9051b121544
Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes
Test custom request
--047d7bf0e8e4de0bc9051b121544
Content-Type: text/calendar; charset=UTF-8; method=REQUEST
Content-Transfer-Encoding: 7bit
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20150721T090000Z
DTEND:20150721T100000Z
DTSTAMP:20150717T134825Z
ORGANIZER;CN=Joe Hu:mailto:sapikachu@gmail.com
UID:ibanvlt787ark3mtjeup15o50s@google.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
TRUE;CN=i@sapikachu.net;X-NUM-GUESTS=0:mailto:i@sapikachu.net
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
TRUE;CN=calendar@sapikachu.net;X-NUM-GUESTS=0:mailto:calendar@sapikachu.net
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE;RSVP=TRU
E;CN=Joe Hu;X-NUM-GUESTS=0:mailto:sapikachu@gmail.com
CREATED:20150717T132253Z
DESCRIPTION:View your event at
LAST-MODIFIED:20150717T134925Z
LOCATION:
SEQUENCE:20
STATUS:CONFIRMED
SUMMARY:RFC2446 Test New From Client 2
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
--047d7bf0e8e4de0bc9051b121544--
--047d7bf0e8e4de0bd8051b121546--"""
print(requests.post(
"https://api.mailgun.net/v3/sapikachu.net/messages.mime",
auth=("api", "<reducted>"),
data={
"to": "sapikachu@gmail.com",
},
files={"message": ("test.eml", body)},
).text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment