Sending Appointments to a BlackBerry

Sending a calendar appointment over the web is usually straight-forward. Most calendar applications understand the iCalendar format and will automatically import the appointment when an iCalendar file is opened (.ics is the common extension for iCalendar files on the Windows platform). The format of the iCalendar file is fairly simple, here’s an example from the Wikipedia page:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:uid1@example.com
DTSTAMP:19970714T170000Z
ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
DTSTART:20111118T170000Z
DTEND:20111118T180000Z
SUMMARY:Test Appointment
END:VEVENT
END:VCALENDAR

Normally, attaching an iCalendar file to an email is sufficient, but BlackBerrys are different. BlackBerrys are special. If you try to download an ics file, or open an ics attachment, you’ll see something like this:

Attachment format not recognised

BlackBerry does understand Microsoft Outlook invitations, so the question is how to replicate an Outlook style invitation without using Outlook…

The solution is to embed the iCalendar format directly into the message body, as an alternative “view”. Before running the code below you’ll need to copy the example iCalendar file above into a text file, and rename it “appointment.ics”.

Only two namespaces are required:

using System.IO;
using System.Net.Mail;

These should be changed to point to your local SMTP or Exchange server, the appointment file, and valid email addresses respectively:

private static const string smtpServer = "SmtpServer";
private static const string appointmentPath = @"C:\appointment.ics";
private static const string fromAddress = "john.doe@example.com";
private static const string toAddress = "john.doe@example.com";

Note: When the BlackBerry user accepts the invitation, an email acknowledgement is sent back to the sender.

Here’s the code:

using (var client = new SmtpClient(smtpServer))
{
    var message = new MailMessage();
    message.From = new MailAddress(fromAddress);
    message.To.Add(new MailAddress(toAddress));
    message.Subject = "New Appointment";

    var stream = File.OpenRead(appointmentPath);
    var view = new AlternateView(stream, "text/calendar");
    message.AlternateViews.Add(view);

    client.Send(message);
}

Full credit goes to Philip Bradbear for introducing me to this technique.

Advertisements
This entry was posted in Tips and Tricks and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s