function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Email MIME Type and iCal (ICS) format

I was wondering if anyone has had experience with this one. Is there a way to set the MIME type of an email sent via APEX? Additionally, I'll want to generate and attach an ICS file with meeting invite details. The ICS file is pretty much a txt file so that shouldn't be that tricky. Has anyone tried this before?
Anyone have any feedback on this one?

I'm also working on ICS generation. No one done this in Salesforce?

Rasmus MenckeRasmus Mencke

Unfortunately this is not possible today, as all attachments are send as "application/octet-stream" that will confuse the email client.


The good news is that in the fall release '09 we will support creation of any content-type you want. That way you can set you attachment as "text/calendar" and have it show up as a calendar invite you can approve or decline.

If you just want an 'Add to Outlook' link in a page, rather than an email, you can also get this working using a VisualForce page. The trick is to ensure you set the Content Type attribute of the page to "text/calendar#filename.ics" and for Internet Explorer support set the cache="true".
Message Edited by bg_richard on 08-03-2009 02:04 PM

We (We as in.. the company I work for) have a requirement for this as well and since the Winter '10 release with the ability to set the content type, maybe the following code might help you. I've managed to get this working in the debug screen. I'm a programming newbie so I haven't made a apex class for this yet (will figure it out sooner or later..) , but this chunk of very messy code produces the inbound appointments that we require for Novell GroupWise 7.



        Messaging.EmailFileAttachment[] attachments = new Messaging.EmailFileAttachment[0];
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
String vCal = 'BEGIN:VCALENDAR' + '\n' + 'PRODID:-// Labs//iCalendar Export//EN' + '\n' +

'VERSION:2.0' + '\n' + 'CALSCALE:GREGORIAN' + '\n' + 'METHOD:REQUEST'+ '\n'+ 'BEGIN:VEVENT'+ '\n' +

'DTSTART:20091008T103000Z' + '\n' + 'DTEND:20091008T113000Z' + '\n' + 'DTSTAMP:20091008T103839Z' + '\n' +

'ORGANIZER;' + '\n' + ''+ '\n' +

'CREATED:20091008T103839Z' + '\n' + 'DESCRIPTION:something' + '\n' + 'LAST-MODIFIED:20091008T103839Z' + '\n' +

'SEQUENCE:0' + '\n' + 'STATUS:CONFIRMED' + '\n' + 'SUMMARY:Go Home Lan' + + '\n' + 'TRANSP:OPAQUE' + '\n' + 





        .... do the rest of the email attachment code


Of course you will need to chuck in your variables and stuff within the iCalendar string, or you can also use the iCalendar Export class thats on the appexchange and inject the additional vcalendar properties to make it work for your requirements.


Good luck! Conceptually it can be done.






         I am getting the following error with the below code. Please advise..

Error: Compile Error: Method does not exist or incorrect signature: [Messaging.EmailFileAttachment].setContentType(String) at line 16 column 9



public class VF_Test
    List<String> toAddresses = new List<String>();
    public VF_Test()
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        Messaging.EmailFileAttachment vcal = new Messaging.EmailFileAttachment();
        Blob fileBody;
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {vcal});
         Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 


Looks like you aren't the only one with the problem:


Hopefully some documentation will pop-up soon (keeping fingers crossed).


Is your test org Winter '10, and have you set the API version of that class to v17.0 ?



        Thanks for the response. I made the class's version as 17.0 and the error is gone. But still I did not get any 

email. If i comment out the Calendar part, I get the normal email. Any ideas?

         Much appreciated


Message Edited by sforce2009 on 10-22-2009 06:04 AM

Is iCal in & out still a topic of interest? I have a very keen interest in this interoperability.

Yes. Ofcourse
I'm having a similar issue here: MIME Settings for ICS as multipart/alternative (

Have any of you figured out how to display an ICS attachment in place of the txt or html version of an email? If so, could you help me with some code samples on the linked discussion? I can attach ICS files, but I cannot get them to display the "accept/reject" features.
Shai FisherShai Fisher
I managed to make Outlook recognize the ics attachment as an invitation, by setting the attachment content type to:
'text/calendar; charset=utf-8; method=REQUEST'