'Why the meeting message is not treated by Mac OS calendar?

I'm writing a Python program that generates an invitation. The code below works approximately. It send the invitation, the invitation is recognized by an Outlook client, but is not treated by Mac OS calendar.

What is missing or what's wrong ?

Thanks

subject = "Mail subject"
sender_email = "[email protected]"
to = ["[email protected]"]
cc = []

# Create the plain-text and HTML version of your message
text = """\
Text message version
"""
html = """\
<!DOCTYPE html><html><head></head><body><p>The HTML message</p></body></html>
"""

# Create a multipart message and set headers
message = MIMEMultipart("mixed")
message["From"] = sender_email
message["To"] = ", ".join(to)
message["Cc"] = ", ".join(cc)
message["Subject"] = subject
message['Date'] = formatdate(localtime=True)

message_alternative = MIMEMultipart('alternative')

message_related = MIMEMultipart('related')
message_related.attach(MIMEText(html, 'html'))
message_alternative.attach(message_related)

#message_alternative.attach((text, 'plain'))

# --- Begin ical integration ---
ical = CreateIcs() # this function return an ICS content
ical_atch = MIMEBase("text", "calendar", method="REQUEST", name="invite.ics")
ical_atch.set_payload(ical)
encoders.encode_quopri(ical_atch)
message_alternative.attach(ical_atch)
# --- END ical integration ---

message.attach(message_alternative)

# convert message to string
text = message.as_string()

# Send mail
host='127.0.0.1'
port=25
context = None
        
with smtplib.SMTP(host=host, port=port) as server:
    server.sendmail(sender_email, message["To"].split(",") + message["Cc"].split(","), text)
print(f"Mail sent TO : {message['To'].split(',')}, CC : {message['Cc'].split(',')}")    


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source