+ Start a Discussion
RRESRRES 

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?
RRESRRES
Anyone have any feedback on this one?
d3developerd3developer

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.

bg_richardbg_richard
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
RiskCoverSystemRiskCoverSystem

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();
        efa.setFileName('rfc2445.ics');
        
        
String vCal = 'BEGIN:VCALENDAR' + '\n' + 'PRODID:-//Force.com 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;CN=lan.pham@icwa.wa.gov.au:mailto:lan.pham@icwa.wa.gov.au' + '\n' + 'UID:lan.pham@icwa.wa.gov.au'+ '\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' + 

'END:VEVENT'+ '\n' + 'END:VCALENDAR';

 

 

        efa.setBody(blob.valueOf(vCal));
        attachments.add(efa);
        efa.setContentType('text/calendar');


        .... 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.

 

-Lan

 

sforce2009sforce2009

Hi,

         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

 

Code:

public class VF_Test
{
    List<String> toAddresses = new List<String>();
    public VF_Test()
    {
        toAddresses.add('sforce2009@gmail.com');
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setSubject('Test');
        email.setToAddresses(toAddresses);
        email.setHtmlBody('Test');
        email.setPlainTextBody('Test');
        Messaging.EmailFileAttachment vcal = new Messaging.EmailFileAttachment();
        vcal.setFileName('Appointment.ics');
        Blob fileBody;
        vcal.setBody(fileBody);
        vcal.setContentType('text/Calendar');
        vcal.setInLine(true);
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {vcal});
         Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
    }
   
}

d3developerd3developer

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

 

http://community.salesforce.com/sforce/board/message?board.id=apex&thread.id=20946

 

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

RiskCoverSystemRiskCoverSystem

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

sforce2009sforce2009

Hi,

        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
MyGodItsColdMyGodItsCold

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

sforce2009sforce2009
Yes. Ofcourse
ilewi121ilewi121
I'm having a similar issue here: MIME Settings for ICS as multipart/alternative (https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AsPlIAK)

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.