Generating iCalendar e-mails

Joined
Jul 5, 2006
Messages
9
Programming Experience
1-3
Hi guys,

I have developed a VB.NET application which monitors a database and sends e-mails with an vCalendar attachment to Lotus Notes clients so that they can import the event to their calendar.

The problem I have is that as the application stands they have to click on the attachment which contains an vCalendar formatted text and import it which is a large number of keyclicks and a pain for the users to do.

If a user sends a calendar event from lotus to another lotus client, even if the lotus client is across the internet (so through plain text SMTP gateways) then they recieve it as a calendar item and can accept it directly and it drops into their calendar. This is what I want to create with my service...

So.. does anyone know of an object library for creating icalendar e-mails which would be interperetted correctly by the lotus client? Alternatively a way that I can format the e-mail so that it is interperetted correctly by the client .. if I just paste the vCalendar text into the body of the e-mail it is just displayed rather than interperetted as a calendar event :-(

Any help is as always hugely appreciated.

Cheers,

Chris
 
Have you tried looking at the header of the email that correctly imports the content ? I am assuming this is what needs to be duplicated.

Steve
 
Hi,

Thanks for that I suspect you have hit the nail on the header (ok dodgy pun)... So far I have only been using standard headers.. Gonna research headers for iCalendar e-mails ...

Thanks

Chris
 
Hi,

Ok it appears that the message header I need to add to my email is:

Content-Type: text/calendar; method=REQUEST;
charset="utf-8"
Content-Transfer-Encoding: 7bit

My problem is now that I have a method of MailMessage that allows me to read the headers in the message but I can't seem to find a method to allow me to set content type (I have boldened the bits where I set the encoding and type)

What a i missing?

Cheers,

Chris

My current code is below:
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] smtpMail [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Web.Mail.SmtpMail[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] MailMessage [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Web.Mail.MailMessage[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] NumSent [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ICS_ID[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strICS [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
 
[SIZE=2]ICS_ID = Year(Now) & Month(Now) & Now.Day & Now.Hour & Now.Minute & Now.Second[/SIZE]
[SIZE=2][COLOR=#008000]'Create the VCARD[/COLOR][/SIZE]
[SIZE=2]strICS = "BEGIN:VCALENDAR" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "VERSION:2.0" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "METHOD:REQUEST" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "BEGIN:VEVENT" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "ATTENDEE;CN=""" & emailto & """;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:" & emailto & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "ORGANIZER:MAILTO:" & emailto & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "DTSTART:" & ICSDate(IsoDate(StartDate)) & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "DTEND:" & ICSDate(IsoDate(EndDate)) & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "LOCATION:" & sLocation & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "TRANSP:OPAQUE" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "SEQUENCE:0" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "UID:" & sbooker & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "DTSTAMP:20060626T104103Z" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "SUMMARY:" & sSubject & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "PRIORITY:5" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "CLASS:PUBLIC" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "BEGIN:VALARM" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "TRIGGER:PT15M" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "ACTION:DISPLAY" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "DESCRIPTION:Reminder" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "END:VALARM" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "END:VEVENT" & vbCrLf[/SIZE]
[SIZE=2]strICS = strICS & "END:VCALENDAR" & vbCrLf[/SIZE]
[SIZE=2][COLOR=#008000]'Write it to a file[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] a [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.IO.StreamWriter = _[/SIZE]
[SIZE=2]System.IO.File.CreateText(Application.StartupPath & "\" & ICS_ID & ".ics")[/SIZE]
[SIZE=2]a.Write(strICS)[/SIZE]
[SIZE=2]a.Close()[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] MailTo [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'Set the SMTP Server[/COLOR][/SIZE]
[SIZE=2]smtpMail.SmtpServer = txtSMTPServer.Text[/SIZE]
[SIZE=2][COLOR=#008000]'Create the Attachment[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] MailAttachment [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Web.Mail.MailAttachment(Application.StartupPath & "\" & ICS_ID & ".ics")[/SIZE]
[SIZE=2][COLOR=#008000]'MailMessage. = txtSMTPServer.Text[/COLOR][/SIZE]
[SIZE=2]MailMessage.From = GetUserEmail(sbooker)[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] Trim(MailMessage.From) = "" [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]MailMessage.From = txtFallbackFrom.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2]MailTo = Trim(GetUserEmail(emailto) & ";" & GetAttendeeEmails(Res_id))[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] Microsoft.VisualBasic.Left(MailTo.Trim, 1) = ";" [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]MailTo = Mid(MailTo, 2, Len(MailTo))[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'MailMessage.To = MailTo.Trim[/COLOR][/SIZE]
[SIZE=2]MailMessage.Subject = sSubject[/SIZE]
[SIZE=2][COLOR=#008000]'MailMessage.Headers()[/COLOR][/SIZE]
[SIZE=2]MailMessage.Body = strICS [/SIZE][SIZE=2][COLOR=#008000]'Substitute_Tags(GetInvitationBody(), Res_id)[/COLOR][/SIZE]
[SIZE=2]MailMessage.Attachments.Add(MailAttachment)[/SIZE]
[SIZE=2][B]MailMessage.BodyEncoding = System.Text.Encoding.UTF7[/B][/SIZE]
[SIZE=2][B]MailMessage.BodyFormat = MailFormat.Text[/B][/SIZE]
[SIZE=2]NumSent = Send_Emails(MailMessage, MailTo, smtpMail)[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] NumSent > 0 [/SIZE][SIZE=2][COLOR=#0000ff]And[/COLOR][/SIZE][SIZE=2] Len(MailMessage.From.Trim) > 3 [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'smtpMail.Send(MailMessage)[/COLOR][/SIZE]
[SIZE=2]CreateICS = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]CreateICS = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2]System.IO.File.Delete(Application.StartupPath & "\" & ICS_ID & ".ics")
[/SIZE]
 
Last edited by a moderator:
Back
Top