0 votes

Gmail doesn't create automatically appointments

by

1 Answer

0 votes
 
Best answer

I just tested it just to be sure, and I'm sure it works.

However Gmail is a strange beast, and some things you need to consider:

1.
You need to send it to a recipient using SMTP.
Uploading it via IMAP won't work.

2.
Make sure all email addresses match (from == organizer, to == participant).

Here's my code to create ical all-day event:

Appointment appointment = new Appointment();

Event newEvent = appointment.AddEvent();
newEvent.SetOrganizer(
    new Person(
        "Sender account", 
        "sender@gmail.com"));
newEvent.AddParticipant(
    new Participant(
        "Recipient account", 
        "recipient@gmail.com"));
newEvent.Description = "description";
newEvent.Summary = "summary";
newEvent.Start = new DateTime(2023, 12, 01, 9, 0, 0);
newEvent.End = new DateTime(2023, 12, 01, 10, 0, 0);
newEvent.AllDay();

Create email message and add appointment:

var builder = new MailBuilder();
builder.Subject = "email subject";
builder.From.Add(new MailBox("sender@gmail.com"));
builder.To.Add(new MailBox("recipient@gmail.com"));
builder.Text = "Some text. Appointment is attached";

builder.AddAppointment(appointment);

IMail email = builder.Create();

... and finally: standard email sending code:

using (Smtp client = new Smtp())
{
    client.ConnectSSL("smtp.gmail.com");

    client.UseBestLogin(
        "sender@gmail.com", 
        "app-password"
    );

    client.SendMessage(email);

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