Search code examples
c#smtpoffice365exchange-servericalendar

Send meeting request to Exchange Online room mailbox


I'm working on a C# WebApi project that requires booking Exchange Online room mailboxes without user interaction.

I noticed when you create a new calendar event in Office 365, it sends messages with .ICS files to unknown domains, but for any Outlook email address it sends a message without attachment, that is recognized as an event invitation anyway. It also sends invitations to room mailboxes if you specify a location, and Exchange automatically accepts them if there aren't conflicts. I need to replicate the same behavior using SMTP in C#.

I tried sending an ICS file as attachment to the room mailbox, but the message is simply ignored. Exchange doesn't seem to recognize these files as event requests. If I open the room mailbox, there aren't any buttons to accept or decline the invitation, but I can see the attachment, and can select "Add to calendar". I need to make Exchange accept the request automatically.

After doing some research, I found a few ways to schedule meetings in C#. One is using Exchange Web Services Managed API, but I've heard it will be deprecated in a couple of years, so I can't use it. There are other options like using Graph, but they have a complex authentication system that requires user interaction to set the credentials. I need to do this, if possible, using SMTP, or some other method with plain username and password authentication.

Do anyone knows why Exchange doesn't recognize ICS files, and if there's any other way to do this with SMTP?

EDIT: Solved. This is the finished code in C#, if anyone is interested:

var calendarBytes = Encoding.UTF8.GetBytes(sb.ToString());
MemoryStream ms = new MemoryStream(calendarBytes);
var ct = new ContentType() { MediaType = "text/calendar", CharSet = "utf-8" , Name = "Part_3.ics" };
ct.Parameters.Add("method", "REQUEST");
Attachment attachment = new Attachment(ms, ct);
attachment.ContentDisposition.DispositionType = DispositionTypeNames.Attachment;
attachment.ContentDisposition.FileName = "Part_3.ics";
message.Attachments.Add(attachment);

Solution

  • Exchange could recognize ICS files, You could missing the iTIP method, both in the content-type:

    Content – Type: text/plain; charset=”utf-8”; method=REQUEST
    name=myCalendar.ics 
    Content-Disposition: attachment; 
    filename=myCalendar.ics
    

    You could reference this link:

    Multipart email with text and calendar: Outlook doesn't recognize ICS