Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICS Attachment Does Not Display as Calendar Invitation in Outlook #1114

Open
tomy137 opened this issue Dec 20, 2024 · 0 comments
Open

ICS Attachment Does Not Display as Calendar Invitation in Outlook #1114

tomy137 opened this issue Dec 20, 2024 · 0 comments

Comments

@tomy137
Copy link

tomy137 commented Dec 20, 2024

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:

  1. Obtain a Well-Formatted ICS File: Use an ICS file that is known to display correctly as a calendar invitation in Outlook.
  2. 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())
  1. Verify Invitation in Outlook: The email arrives in the recipient's inbox, and the ICS file is interpreted as a calendar invitation.
    image
  2. 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()
  1. 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.
    image

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant