+1 vote

Is there is a way to cancel icalendar already sent, by sending email cancellation?

by
edited by
Your effort is highly appreciated, but it only send an email with the date, but I need to remove the appointment from the calendar when just the user open the email, OR AT LEAST gives the user a button (like add to calendar button), to remove it from his calendar.
waiting for your response, and thanks in advance.

1 Answer

0 votes
 
Best answer

Of course. You need to use Appointment.Cancel - it creates an appointment with all events canceled:

 Appointment appointment = new Appointment();
 Event newEvent = appointment.AddEvent();

 newEvent.SetOrganizer(new Person("Alice", "alice@gmail.com"));
 newEvent.AddParticipant(new Participant("Bob", "bob@gmail.com"));
 newEvent.Description = "description";
 newEvent.Summary = "summary";
 newEvent.Start = new DateTime(2012, 12, 01, 9, 0, 0);
 newEvent.End = new DateTime(2012, 12, 01, 10, 0, 0);
 newEvent.Priority = 5;
 newEvent.Class = EventClass.Public;
 newEvent.AllDay();

 Alarm alarm = newEvent.AddAlarm();
 alarm.Description = "Reminder";
 alarm.BeforeStart(TimeSpan.FromMinutes(5));

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

 var builder = new MailBuilder();
 builder.Subject = "email subject";
 builder.To.Add(new MailBox("alice@gmail.com", "Alice"));
 builder.From.Add(new MailBox("bob@gmail.com", "Bob"));
 builder.Text = "Some text. Appointment is attached";
 builder.AddAppointment(appointment);
 IMail emailCreate = builder.Create();

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

     client.SendMessage(emailCreate);

     client.Close();
 }

Update:

Appointment appointment2 = new Appointment();
Event e2 = appointment2.AddEvent();
e2.SetOrganizer(new Person("Alice", "alice@gmail.com"));
e2.AddParticipant(new Participant("Bob", "bob@gmail.com"));
e2.Description = "description";
e2.Summary = "summary";
e2.Start = new DateTime(2021, 12, 1, 11, 0, 0);  // changed
e2.End = new DateTime(2021, 12, 1, 12, 0, 0);  // changed

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

Appointment update = appointment2.Update();

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

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

    client.SendMessage(emailCancel);

    client.Close();
}

Cancel:

Appointment appointment2 = new Appointment();
Event e2 = appointment2.AddEvent();
e2.SetOrganizer(new Person("Alice", "alice@gmail.com"));
e2.AddParticipant(new Participant("Bob", "bob@gmail.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@gmail.com"));
builder2.To.Add(new MailBox("bob@gmail.com"));
builder2.AddAppointment(cancel);
IMail emailCancel = builder2.Create();

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

    client.SendMessage(emailCancel);

    client.Close();
}
by (297k points)
selected by
...