0 votes

I created an appointment and sent an email using Limilabs. Now I have a scenario where I need to cancel that appointment. I already tried sample code given in
"Canceling icalendar already sent appointment" , but it doesn't work. Outlook still show that event as Active.

by

1 Answer

0 votes

Canceling icalendar already sent appointment
(https://www.limilabs.com/qa/1377/canceling-icalendar-already-sent-appointment)
provides a correct way of doing this.

Remember that you must use the same event's UID and correct sequence number.
For example Gmail also requires all other properties to match.

Appointment appointment = new Appointment();
Event e = appointment.AddEvent();
e.SetOrganizer(new Person("Alice", "alice@example.com"));
e.AddParticipant(new Participant("Bob", "bob@example.com"));
e.Description = "description";
e.Summary = "summary";
e.Start = new DateTime(2021, 12, 5, 9, 0, 0);
e.End = new DateTime(2021, 12, 5, 10, 0, 0);

string originalUID = e.UID;
int? originalSequence = e.Sequence;

var builder = new MailBuilder();
builder.Subject = "Appointment";
builder.From.Add(new MailBox("alice@example.com"));
builder.To.Add(new MailBox("bob@example.com"));
builder.AddAppointment(appointment);
IMail emailCreate = builder.Create();


using (Smtp client = new Smtp())
{
    client.ConnectSSL("imap.example.com");
    client.UseBestLogin("alice@example.com", "pass");

    client.SendMessage(emailCreate);

    client.Close();
}

Cancel appointment:

Appointment appointment2 = new Appointment();
Event e2 = appointment2.AddEvent();
e2.SetOrganizer(new Person("Alice", "alice@example.com"));
e2.AddParticipant(new Participant("Bob", "bob@example.com"));
e2.Description = "description";
e2.Summary = "summary";
e2.Start = new DateTime(2021, 12, 5, 9, 0, 0);
e2.End = new DateTime(2021, 12, 5, 10, 0, 0);

e2.UID = originalUID;
e2.Sequence = originalSequence;

Appointment cancel = appointment2.Cancel();

var builder2 = new MailBuilder();
builder2.Subject = "Appointment";
builder2.From.Add(new MailBox("alice@example.com"));
builder2.To.Add(new MailBox("bob@example.com"));
builder2.AddAppointment(cancel);
IMail emailCancel = builder2.Create();

using (Smtp client = new Smtp())
{
    client.ConnectSSL("imap.example.com");
    client.UseBestLogin("alice@example.com", "pass");

    client.SendMessage(emailCancel);

    client.Close();
}
by (301k points)
edited by
...