Send iCalendar meeting requests for different timezone

Usually you define time of an event in relation to current time zone. If you want to send such event to recipient in different time zone you should use UTC. This way you can be sure that you both meet at correct time.

First add all necessary namespaces:

// C# version

using System;
using Limilabs.Mail;
using Limilabs.Mail.Appointments;
using Fluent = Limilabs.Mail.Fluent;
using Limilabs.Client.SMTP;
' VB.NET version

Imports System;
Imports Limilabs.Mail;
Imports Limilabs.Mail.Appointments;
Imports Fluent = Limilabs.Mail.Fluent;
Imports Limilabs.Client.SMTP;

The easiest way to achieve this is to create specify time using local DateTime instance and invoke ToUniversalTime method, which translates it to UTC timezone. This also handles daylight saving time differences.

You can also use overloaded DateTime constructor that uses UTC timezone: DateTime(2012, 08, 17, 12, 00, 00, DateTimeKind.Utc).

// C#

DateTime start = new DateTime(2012, 08, 17, 12, 00, 00).ToUniversalTime();

Appointment appointment = new Appointment();
Event e = appointment.AddEvent();
e.Start = start;
e.End = start + TimeSpan.FromMinutes(30);
e.Summary = "At noon";

e.SetOrganizer(new Person("Alice", "alice@example.org"));

e.AddParticipant(
new Participant("Bob", "bob@example.org", ParticipationRole.Required, true));
e.AddParticipant(
new Participant("Tom", "tom@example.org", ParticipationRole.Optional, true));
e.AddParticipant(
new Participant("Alice", "alice@example.org", ParticipationRole.Required, true));

Alarm alarm = e.AddAlarm();
alarm.BeforeStart(TimeSpan.FromMinutes(15));

IMail email = Fluent.Mail
.Text("Status meeting at noon.")
.Subject("Status meeting")
.From("alice@example.org")
.To("bob@example.org")
.To("tom@example.org")
.AddAppointment(appointment)
.Create();

using (Smtp client = new Smtp())
{
client.ConnectSSL("smtp.example.org");
client.UseBestLogin("user", "password");
client.SendMessage(email);
client.Close();
}
' VB.NET

Dim start As DateTime = New DateTime(2012, 8, 17, 12, 0, 0).ToUniversalTime()

Dim appointment As New Appointment()
Dim e As [Event] = appointment.AddEvent()
e.Start = start
e.[End] = start + TimeSpan.FromMinutes(30)
e.Summary = "At noon"

e.SetOrganizer(New Person("Alice", "alice@example.org"))

e.AddParticipant( _
New Participant("Bob", "bob@example.org", ParticipationRole.Required, True))
e.AddParticipant( _
New Participant("Tom", "tom@example.org", ParticipationRole.[Optional], True))
e.AddParticipant( _
New Participant("Alice", "alice@example.org", ParticipationRole.Required, True))

Dim alarm As Alarm = e.AddAlarm()
alarm.BeforeStart(TimeSpan.FromMinutes(15))

Dim email As IMail = Fluent.Mail.Text("Status meeting at noon.") _
.Subject("Status meeting") _
.From("alice@example.org") _
.[To]("bob@example.org") _
.[To]("tom@example.org") _
.AddAppointment(appointment) _
.Create()

Using client As New Smtp()
client.ConnectSSL("smtp.example.org")
client.UseBestLogin("user", "password")
client.SendMessage(email)
client.Close()
End Using

Things get a bit more complicated if you want to define recurring event in different timezone. You can not use UTC time zone in such case.

Tags:     

Questions?

Consider using our Q&A forum for asking questions.