We help IT Professionals succeed at work.
Get Started

An iCalendar (ics) email attachment fails to import into Outlook.

SiriusPhil
SiriusPhil asked
on
4,312 Views
Last Modified: 2013-12-24
I have created the following CFC based on a UDF I found online somewhere.  It basically creates a .ics (iCalendar) file that is e-mailed to a client.  The event is accepted by iCal on the Mac but fails when someone with MS Outlook tries to open it.    I even added a bunch of fields that I noticed in an icalendar event sent from Outlook but it still fails.    I also added the contents of the generated ics file below...

Any suggestion?

===========The CFC======================

<cfcomponent>

      <cffunction name="iCal" access="public" returntype="string">
      
        <cfargument name="EventID" type="numeric" required="no" default="1">
        <cfquery name="stEvent" datasource="#application.dsn#">
        SELECT Title as subject,"Host", (City + '\, ' + State) as location, StartDate as StartTime, EndDate as EndTime, Description, contactemail, '1' as Priority
        FROM dbo.tbl_calendar WHERE EventID = #Arguments.EventID#
        </cfquery>
        <cfset vCal = "">
        <cfset CRLF = "#chr(13)#">
      
      <cfscript>

      
      if (NOT IsDefined("stEvent.StartTime"))
            stEvent.StartTime = DateConvert('local2Utc', Now());
      
      //if (NOT IsDefined("stEvent.EndTime"))
            //stEvent.EndTime = DateConvert('local2Utc', Now());
            
      if (NOT IsDefined("stEvent.location"))
            stEvent.location = "N/A";
                        
      if (NOT IsDefined("stEvent.subject"))
            stEvent.subject = "Auto vCalendar Generated";
            
      if (NOT IsDefined("stEvent.description"))
            stEvent.description = "Autobot VCalendar Generated";
            
      if (NOT IsDefined("stEvent.priority"))
            stEvent.priority = "1";
                  

      vCal = "BEGIN:VCALENDAR" & CRLF;
      vCal = vCal & "PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN" & CRLF;
      vCal = vCal & "VERSION:2.0" & CRLF;
      vCal = vCal & "METHOD:PUBLISH" & CRLF;
      vCal = vCal & "BEGIN:VEVENT" & CRLF;
      vCal = vCal & "ORGANIZER:MAILTO:support@siriusinnovations.com" & CRLF;
      vCal = vCal & "DTSTART:" & 
                  DateFormat(stEvent.StartTime,"yyyymmdd") & "T" & 
                  TimeFormat(stEvent.StartTime, "HHmmss") & "Z" & CRLF;
      vCal = vCal & "DTEND:" & 
                  DateFormat(stEvent.StartTime,"yyyymmdd") & "T" & 
                  TimeFormat(stEvent.StartTime, "HHmmss") & "Z" & CRLF;
      vCal = vCal & "LOCATION:" & stEvent.location & CRLF;
      vCal = vCal & "TRANSP:OPAQUE"  & CRLF;
      vCal = vCal & "SEQUENCE:0"  & CRLF;
      vCal = vCal & "DESCRIPTION:";
      // Convert CF_CRLF (13_10) into =0D=0A with CR/LF and indent sequences
      description = REReplace(stEvent.description,"[#Chr(13)##Chr(10)#]", "=0D=0A=#Chr(13)##Chr(10)#     ", "ALL");
      vCal = vCal & description & CRLF;
      vCal = vCal & "SUMMARY:" & stEvent.subject & CRLF;
      vCal = vCal & "PRIORITY:" & stEvent.priority & CRLF;
      vCal = vCal & "CLASS:PUBLIC" & CRLF;
      vCal = vCal & "END:VEVENT" & CRLF;
      vCal = vCal & "END:VCALENDAR";      
      </cfscript>
             
      <cffile action="write" file="D:\Websites\test\sandbox\vcaltest.ics" output="#vcal#">
      <cfmail to="phayes@xxxs.com" from="phayes@xxx.com" subject="Vcal Test">
      <cfmailparam file="D:\Websites\test\sandbox\vcaltest.ics">
    </cfmail>
      
       <cfset Status = "Success!">
      
        <cfreturn status>
      </cffunction>
==================================

=========The contents of the ICS file=========

BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
ORGANIZER:MAILTO:support@siriusinnovations.com
DTSTART:20050916T000000Z
DTEND:20050916T000000Z
LOCATION:Norwalk\, CT
TRANSP:OPAQUE
SEQUENCE:0
DESCRIPTION:The MAC meeting is scheduled for Wednesday, June 16, 2004 1 p.m. at Norwalk Hospital Emergency Department Conference Room.
SUMMARY:Medical Advisory Committee (MAC) Meeting
PRIORITY:1
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR
=======================
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE