I'm trying to send an ics file attached to an email so the recipient(s) get an appointment invitation.
For a variety of reasons I can't use appointment sync to send the invites.
My code is working fine when the recipient is @googlemail.com but when their on Exchange, the attachment doesn't give the expected Accept/Decline/etc. buttons unless you open the attachment.
I have tried a variety of methods but the ones I think should work are:
- Setting the MimeType of the email to "multipart/mixed"
- Setting the MimeType of the attached file to "text/calendar" (possibly with ";method=REQUEST)
BEGIN:VCALENDAR PRODID:-//Voyager Software//Training//EN VERSION:2.0 CALSCALE:GREGORIAN METHOD:REQUEST X-MS-OLK-FORCEINSPECTOROPEN:TRUE BEGIN:VEVENT DTSTART:20190406T133000Z DTEND:20190406T143000Z DTSTAMP:20190402T130711Z ORGANIZER;CN=The Organizer:mailto:me@us.com UID:bfnuadapfgs91eqihepacgq2lm@us.com ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE;CN=The Organizer;X-NUM-GUESTS=0:mailto:me@us.com ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=the recipient;X-NUM-GUESTS=0:mailto:you@them.com CREATED:20190402T130709Z DESCRIPTION:some description LAST-MODIFIED:20190402T130709Z LOCATION:somehwere X-ALT-DESC;FMTTYPE=text/html:<html><body><a href='http://bing.com'>Bing</a></body></html> SEQUENCE:0 STATUS:CONFIRMED SUMMARY:test TRANSP:OPAQUE END:VEVENT END:VCALENDAR
The code to create the email and the file:
var email = new Email
{
To = new ActivityParty[] { toParty, },
From = new ActivityParty[] { fromParty },
Subject = "Test Appointment",
Description = "Please open the attached file to accept the appointment.",
DirectionCode = true,
MimeType = "multipart/mixed"
};
Console.WriteLine("Create Email");
Guid gEmail = service.Create(email);
var ical = new Entity("activitymimeattachment");
ical["mimetype"] = "text/calendar";//;method=REQUEST
ical["body"] = appointment.GetICS();//Base64 encoded version of vCalendar above
ical["subject"] = "Appointment";
ical["filename"] = appointment.Filename;
ical["objectid"] = new EntityReference("email", gEmail);
ical["objecttypecode"] = email.LogicalName;
Console.WriteLine("Create Attachment");
service.Create(ical);
SendEmailRequest sendEmailreq = new SendEmailRequest
{
EmailId = gEmail,
TrackingToken = "",
IssueSend = true
};
Console.WriteLine("Send Email");
SendEmailResponse sendEmailresp = (SendEmailResponse)service.Execute(sendEmailreq);







