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", ""));

    new Participant("Bob", "", ParticipationRole.Required, true));
    new Participant("Tom", "", ParticipationRole.Optional, true));
    new Participant("Alice", "", ParticipationRole.Required, true));

Alarm alarm = e.AddAlarm();

IMail email = Fluent.Mail
    .Text("Status meeting at noon.")
    .Subject("Status meeting")

using (Smtp client = new Smtp())
    client.UseBestLogin("user", "password");

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", ""))

e.AddParticipant( _
	New Participant("Bob", "", ParticipationRole.Required, True))
e.AddParticipant( _
	New Participant("Tom", "", ParticipationRole.[Optional], True))
e.AddParticipant( _
	New Participant("Alice", "", ParticipationRole.Required, True))

Dim alarm As Alarm = e.AddAlarm()

Dim email As IMail = Fluent.Mail.Text("Status meeting at noon.") _
	.Subject("Status meeting") _
	.From("") _
	.[To]("") _
	.[To]("") _
	.AddAppointment(appointment) _

Using client As New Smtp()
	client.UseBestLogin("user", "password")
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: , , , ,


Consider using our Q&A forum for asking any questions.