Open
Description
Hello,
I am encountering an issue where an ICS file attached to an email does not appear as a calendar invitation in Outlook when the email is sent using the O365 Python library.
Problem Details:
- SMTP Works: When sending the same ICS file via an SMTP client, the email is correctly interpreted as a calendar invitation in Outlook.
- O365 Fails: When sending the same ICS file using the O365 Python library, the ICS file is treated as a regular attachment, and Outlook does not display it as a calendar invitation.
Additional Information:
- The ICS file itself is not faulty, as it works as expected when sent through SMTP.
- I observed differences in the email headers and formatting between emails sent via SMTP and those sent using O365. These differences might be causing the issue.
Steps to Reproduce:
- Obtain a Well-Formatted ICS File: Use an ICS file that is known to display correctly as a calendar invitation in Outlook.
- Send via SMTP: Use the following code to send the ICS file via SMTP:
import smtplib
from email.mime.multipart import MIMEMultipart
ical = """
# ** Well-Formatted ICS File **
"""
msg = MIMEMultipart()
msg.attach( MIMEText(ical,'calendar;method=REQUEST') )
# add to, from etc.
mailserver = smtplib.SMTP(****,587)
# login etc.
mailserver.sendmail(fromaddrs,toaddrs,msg.as_string())
- Verify Invitation in Outlook: The email arrives in the recipient's inbox, and the ICS file is interpreted as a calendar invitation.
- Send via O365: Use the following code to send the same ICS file via the O365 Python library:
mailbox = account.mailbox()
message = mailbox.new_message()
message.to.add('***')
message.sender.address = "***"
message.sender.name = '****'
message.subject = '****'
message.body = "*****"
message.attachments.add([(io.BytesIO(OLD_ICS.encode('utf-8')), "invite.ics")])
#I've tried with and without this other lines and different combinaisons :
message.attachments[0].contentType = "text/calendar; method=REQUEST; charset=UTF-8"
message.attachments[0].contentId = 'cid:calendar-invite'
message.attachments[0].is_inline = True
message.send()
- Observe the Result: The email arrives, but the ICS file is treated as a plain attachment, and the calendar invitation is not displayed in Outlook.
Additional Observations:
I compared the eml
files generated by both methods (SMTP vs O365) and noticed the following differences:
SMTP Email:
- Content-Type:
multipart/mixed;
- Attachments:
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64
Content-Type: text/calendar; method="REQUEST"; charset="utf-8"
Content-Transfer-Encoding: base64
O365 Email:
- Content-Type:
multipart/related; type="multipart/alternative"
- Attachments:
Content-Type: multipart/alternative;
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Type: text/calendar; name="invite.ics"
Content-Description: invite.ics
Content-Disposition: inline; filename="invite.ics"; size=3257; creation-date="Fri, 20 Dec 2024 13:54:06 GMT"; modification-date="Fri, 20 Dec 2024 13:54:06 GMT"
Content-Transfer-Encoding: base64
I don't really know what to deduce from this and whether it's relevant or not...
Have you ever managed to do this?