I am attempting to attach an ics file to an email using the SendGrid sdk provided by them for C#.
Here's my code:
using SendGrid;
using SendGrid.Helpers.Mail;
----
var client = new SendGridClient(APIKey);
var from = new EmailAddress(email.From);
var to = new EmailAddress(email.To);
var msg = MailHelper.CreateSingleEmail(from, to, "test", "test");
var testcontent = "BEGIN:VCALENDAR" + Environment.NewLine;
testcontent += "PRODID:-//Google Inc//Google Calendar 70.9054//EN" + Environment.NewLine;
testcontent += "VERSION:2.0" + Environment.NewLine;
testcontent += "CALSCALE:GREGORIAN" + Environment.NewLine;
testcontent += "METHOD:REQUEST" + Environment.NewLine;
testcontent += "BEGIN:VEVENT" + Environment.NewLine;
testcontent += "DTSTART:20220418T003000Z" + Environment.NewLine;
testcontent += "DTEND:20220418T010000Z" + Environment.NewLine;
testcontent += "DTSTAMP:20220418T001419Z" + Environment.NewLine;
testcontent += "ORGANIZER;CN=Your Name:mailto:yourname@youremail.com" + Environment.NewLine;
testcontent += "UID:2gfanpbtlo35h4dk5qg53c6msa@google.com" + Environment.NewLine;
testcontent += "ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=anotheremail@email.com;X-NUM-GUESTS=0:mailto:anotheremail@email.com" + Environment.NewLine;
testcontent += "ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE;CN=Your Name;X-NUM-GUESTS=0:mailto:yourname@youremail.com" + Environment.NewLine;
testcontent += "X-MICROSOFT-CDO-OWNERAPPTID:404715488" + Environment.NewLine;
testcontent += "CREATED:20220418T001418Z" + Environment.NewLine;
testcontent += "DESCRIPTION:test" + Environment.NewLine;
testcontent += "LAST-MODIFIED:20220418T001418Z" + Environment.NewLine;
testcontent += "LOCATION:" + Environment.NewLine;
testcontent += "SEQUENCE:0" + Environment.NewLine;
testcontent += "STATUS:CONFIRMED" + Environment.NewLine;
testcontent += "SUMMARY:test" + Environment.NewLine;
testcontent += "TRANSP:OPAQUE" + Environment.NewLine;
testcontent += "END:VEVENT" + Environment.NewLine;
testcontent += "END:VCALENDAR";
var base64 = Encoding.UTF8.GetBytes(testcontent);
var attachment = new Attachment();
attachment.Content = Convert.ToBase64String(base64);
attachment.Filename = email.AttachmentName;
attachment.Disposition = "attachment";
attachment.Type = "text/calendar;method=request";
msg.AddAttachment(attachment);
var sg_response = client.SendEmailAsync(msg).GetAwaiter().GetResult();
This code sends the email just fine however I receive the ics file that is attached as a simple attachment and not as a "properly interpreted" calendar invite.
For example, if I use Gmail to create a calendar item and invite an email account that uses Outlook I receive an email that looks like the following:
Now if I use the above snippet of code to send the exact same ICS file that was generated by Gmail, it simply displays as an attachment. Like the following:
So clearly the issue is not the formatting of the contents of ICS file itself but something in how I am transmitting the email to SendGrid or how I am attaching the ICS file to the email message.
However everything I've seen on Stack Overflow seems to point to making sure the MIME/Content-Type is "text/calendar" but I feel like I'm doing this correctly and it doesn't seem to matter what I do.