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();
}