Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
487 views
in Technique[技术] by (71.8m points)

python - Cannot see event title in the email invitation on Microsoft Outlook

The event invitation sent by my python code to Microsoft Outlook does not show the event heading and description.

if __name__ == "__main__":
    sender = PersonInfo("MY NAME", "[email protected]")
    rec1= PersonInfo("MY NAME", "[email protected]")
    rec2= PersonInfo("NAME", "ID2gmail.com")
    recipients = [rec1, rec2]
    subject = "Hi"
    body = "How is everything?"


    dtstart = datetime(2020, 9, 3, 22, 15, 0)
    dtend = datetime(2020, 9, 3, 22, 30, 0)

    ics = build_cal_event("ImpEvent", "Greeting", sender, recipients, dtstart, dtend) #Creates ICS file

    with open("event.ics", 'w') as f:
        f.write(ics)
        
    SendCalendarInvite(sender, recipients, subject, body, ics)

The function build_cal_event is as follows (omitted some of the code for brevity):

def build_cal_event(event_name, event_description, 
                  organizer, attendees,
                  dtstart, dtend):
    # cal = icalendar.Calendar()
    str_list = []
    str_list.append('''
BEGIN:VCALENDAR
METHOD:REQUEST
..........
END:VEVENT
END:VCALENDAR
'''.format(datetime.now().strftime("%Y%m%dT%H%M%SZ")))

    
    cal = ''.join(str_list)
    return cal

It generates the following ICS file (replaced IDs and names to preserve confidentiality):

BEGIN:VCALENDAR
METHOD:REQUEST
PRODID:myOrgName
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Eastern Standard Time
BEGIN:STANDARD
DTSTART:16010101T020000
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
ORGANIZER;CN=ID:mailto:[email protected]
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=ID:
 mailto:[email protected]
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=ID:
 mailto:[email protected]
DESCRIPTION;LANGUAGE=en-US:impevent
UID:81d19fd7-833d-4d56-8d2d-1a343dee77b1
SUMMARY;LANGUAGE=en-US:ImpEvent
DTSTART;TZID=Eastern Standard Time:20200903T221500
DTEND;TZID=Eastern Standard Time:20200903T223000
CLASS:PUBLIC
PRIORITY:5
DTSTAMP:20200903T215335Z
TRANSP:OPAQUE
STATUS:CONFIRMED
SEQUENCE:0
LOCATION;LANGUAGE=en-US:
X-MICROSOFT-CDO-APPT-SEQUENCE:0
X-MICROSOFT-CDO-OWNERAPPTID:2118692743
X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-CDO-INSTTYPE:0
X-MICROSOFT-ONLINEMEETINGEXTERNALLINK:
X-MICROSOFT-ONLINEMEETINGCONFLINK:
X-MICROSOFT-DONOTFORWARDMEETING:FALSE
X-MICROSOFT-DISALLOW-COUNTER:FALSE
X-MICROSOFT-LOCATIONS:[]
BEGIN:VALARM
DESCRIPTION:REMINDER
TRIGGER;RELATED=START:-PT15M
ACTION:DISPLAY
END:VALARM
END:VEVENT
END:VCALENDAR

The SendCalendarInvite function is as follows:

def SendCalendarInvite(sender, recipients, subject, body, ics=None):
    aws_region = "us-east-1"
    client = boto3.client('ses',region_name=aws_region)
    
    msg = MIMEMultipart('mixed')
    
    msg["Subject"] = subject
    msg["From"] = sender.email
    msg["To"] = ', '.join(map(lambda x: x.email, recipients))
    msg["Content-class"] = "urn:content-classes:calendarmessage"

    ics_name = "{}.ics".format(subject.replace(" ", "_").upper())


    part_email = MIMEText(body,"html")
    part_cal = MIMEText(ics,'calendar;method=REQUEST')

    msgAlternative = MIMEMultipart('alternative')
    msg.attach(msgAlternative)
    

    ics_name = "{}.ics".format(subject.replace(" ", "_").upper())
    ical_atch = MIMEBase('text', 'calendar', **{'method' : 'REQUEST', 'name' : ics_name})    
    ical_atch.set_payload(ics)
    ical_atch.set_type('text/calendar; charset=UTF-8; method=REQUEST; component = VEVENT')
    encoders.encode_base64(ical_atch)
    ical_atch.add_header('Content-Type', 'text/calendar')
    ical_atch.add_header('charset', 'UTF-8')
    ical_atch.add_header('component', 'VEVENT')
    ical_atch.add_header('method', 'REQUEST')
    ical_atch.add_header('Content-class', 'urn:content-classes:calendarmessage')
    ical_atch.add_header('Content-Disposition', "attachment; filename={}".format(ics_name))
    ical_atch.add_header('Content-ID', 'calendar_message')
    ical_atch.add_header('Content Description', ics_name)
    ical_atch.add_header("Filename", ics_name)
    ical_atch.add_header("Path", ics_name)

    eml_atch = MIMEText('', 'plain')
    encoders.encode_base64(eml_atch)
    eml_atch.add_header('Content-Transfer-Encoding', "")
    msgAlternative.attach(part_email)
    msgAlternative.attach(part_cal)
    
    try:
        result = client.send_raw_email(
            Source=msg['From'],
            Destinations=[recipient.email for recipient in recipients],
            RawMessage={'Data': msg.as_string()}
        )
    except ClientError as e:
        print(e.response['Error']['Message'])
    else:
        print("Email sent! Message ID:"),
        print(result['MessageId'])

The gmail recipient sees the invitation in this way:

enter image description here

It looks okay.

However, the event invitation for the Outlook recipient looks like this:

enter image description here

The event name and event description are missing in the invitation received by Outlook. How can I ensure that Outlook correctly processes the event invitation sent by my code and shows the event name and description?

EDIT 1:

The mime email looks like this:

Content-Type: multipart/mixed; boundary="===============1597738219983052864=="
MIME-Version: 1.0
Subject: Hi
From: [email protected]
To: [email protected], [email protected]
Content-class: urn:content-classes:calendarmessage

--===============1597738219983052864==
Content-Type: multipart/alternative; boundary="===============6779992366809651548=="
MIME-Version: 1.0

--===============6779992366809651548==
Content-Type: text/html; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

How is everything?
--===============6779992366809651548==
MIME-Version: 1.0
Content-Type: text/calendar; method="REQUEST"; charset="us-ascii"
Content-Transfer-Encoding: 7bit

BEGIN:VCALENDAR
METHOD:REQUEST
PRODID:OrgName
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Eastern Standard Time
BEGIN:STANDARD
DTSTART:16010101T020000
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
ORGANIZER;CN=MYNAME:mailto:[email protected]
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=MYNAME:
 mailto:[email protected]
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=NAME:
 mailto:[email protected]
DESCRIPTION;LANGUAGE=en-US:impevent
UID:f250a41d-84c0-4f12-be83-38d2d51f5586
SUMMARY;LANGUAGE=en-US:ImpEvent
DTSTART;TZID=Eastern Standard Time:20200903T221500
DTEND;TZID=Eastern Standard Time:20200903T223000
CLASS:PUBLIC
PRIORITY:5
DTSTAMP:20200904T122939Z
TRANSP:OPAQUE
STATUS:CONFIRMED
SEQUENCE:0
LOCATION;LANGUAGE=en-US:
X-MICROSOFT-CDO-APPT-SEQUENCE:0
X-MICROSOFT-CDO-OWNERAPPTID:2118692743
X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-CDO-INSTTYPE:0
X-MICROSOFT-ONLINEMEETINGEXTERNALLINK:
X-MICROSOFT-ONLINEMEETINGCONFLINK:
X-MICROSOFT-DONOTFORWARDMEETING:FALSE
X-MICROSOFT-DISALLOW-COUNTER:FALSE
X-MICROSOFT-LOCATIONS:[]
BEGIN:VALARM
DESCRIPTION:REMINDER
TRIGGER;RELATED=START:-PT15M
ACTION:DISPLAY
END:VALARM
END:VEVENT
END:VCALENDAR

--===============6779992366809651548==--

--===============1597738219983052864==--

EDIT 2:

My concern is why is the event name not being detected when the mime email contains it: DESCRIPTION;LANGUAGE=en-US:impevent

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...