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
BittusBittus 

Sending a meeting invitation from salesforce to outlook

Hi ,
I am trying to send a meeting invitation from salesforce to outlook or Gmail with meeting date and time. I have a code to do this, but it is hardcoded. I need to send the meeting invitation with date and time as mentioned by the user.

Here is the code:-
Vf page:-

<apex:page controller="SendEmail">
    <apex:form >
        <apex:pageblock >
            <apex:pageblocksection columns="2">
                <apex:outputText value="Email"/><br/>
                <apex:inputText value="{!sendTo}"/><br/>
                <apex:outputText value="Subject"/><br/>
                <apex:inputText value="{!subject}" maxlength="80"/><br/>
                <apex:inputField value="{!objEvent.ActivityDate}" /><br/>
                <apex:inputField value="{!objEvent.StartDateTime}" /><br/>
                <apex:inputField value="{!objEvent.Description}" /><br/>
                <apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($CurrentPage.parameters.start,':',''),'-',''),' ','T')}"/>
            </apex:pageblocksection>
        </apex:pageblock>
        
             <!---   <apex:inputField value="{!objEvent.starttime}" /> -->
                <apex:commandButton value="send" action="{!sendInvite}"/>
    </apex:form>
</apex:page>

Controller:-

public class SendEmail {
    public String sendTo { get; set; }
    public String Subject { get; set; }
    public Event objEvent{get;set;}
    public SendEmail() {}
    public PageReference sendInvite() {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {sendTo};
        mail.setToAddresses(toAddresses);
        mail.setSubject(Subject);
        mail.setPlainTextBody('');
        Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
        attach.filename = 'meeting.ics';
        attach.ContentType = 'text/calendar;';
        attach.inline = true;
        attach.body = invite();
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] {attach});
        Messaging.SendEmailResult[] er = Messaging.sendEmail(new Messaging.Email[] {mail});
        return null;
    }
    private Blob invite() {
        String txtInvite = '';
 
        txtInvite += 'BEGIN:VCALENDAR\n';
        txtInvite += 'PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN\n';
        txtInvite += 'VERSION:2.0\n';
        txtInvite += 'METHOD:PUBLISH\n';
        txtInvite += 'X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n';
        txtInvite += 'BEGIN:VEVENT\n';
        txtInvite += 'CLASS:PUBLIC\n';
        txtInvite += 'CREATED:20150709T083709Z\n';
        txtInvite += 'DTEND:20150709T010000Z\n';
        txtInvite += 'DTSTAMP:20150708T203709Z\n';
        txtInvite += 'DTSTART:20150709T000000Z\n';
        txtInvite += 'LAST-MODIFIED:20150708T203709Z\n';
        txtInvite += 'LOCATION:Online\n';
        txtInvite += 'PRIORITY:5\n';
        txtInvite += 'SEQUENCE:0\n';
        txtInvite += 'SUMMARY;';
        txtInvite += 'LANGUAGE=en-us:Meeting\n';
        txtInvite += 'TRANSP:OPAQUE\n';
        txtInvite += 'UID:4036587160834EA4AE7848CBD028D1D200000000000000000000000000000000\n';
        txtInvite += 'X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD><META NAME="Generator" CONTENT="MS Exchange Server version 08.00.0681.000"><TITLE></TITLE></HEAD><BODY><!-- Converted from text/plain format --></BODY></HTML>\n';
        txtInvite += 'X-MICROSOFT-CDO-BUSYSTATUS:BUSY\n';
        txtInvite += 'X-MICROSOFT-CDO-IMPORTANCE:1\n';
        txtInvite += 'END:VEVENT\n';
        txtInvite += 'END:VCALENDAR';
 
        return Blob.valueOf(txtInvite);
    }
}
Ashish DeoAshish Deo
Hey Bittus,

Did you find any workaround? I am also facing same issue.

Regards,
Ashish Deo
deo.ashish9999@gmail.com
Manoj ParidaManoj Parida
Hi all,

I have similar requirement and simple. I want to send a calender invite from a specific email address to users in outlook from Salesforce. Once users receive invitation they should be able to accept/decline. I dont want the invite to be sent as an ics attachment rather it should be a plain invite. Can someone help me please? Any reference/code sample?

​Manoj
Kiran ThatikayalaKiran Thatikayala
Hi Manoj, 

We had similar issue with Outlook invites sent from Apex, Outlook invites  were going as ics attachments rather than invites.

We fixed the issue by changing  the below line:

In the above SendEmail class above change the 

attach.ContentType = 'text/calendar;';

TO

attach.ContentType ='text/calendar; charset=utf-8; method=REQUEST';

Hope this resolves your issue.

Please mark it as best answer if it works.

Regards
Kiran Thatikayala
MURALIKRISHNA ARIKOLAMURALIKRISHNA ARIKOLA
Thanks Kiran, It is working 
Dedeepya MunjuluriDedeepya Munjuluri
Hi Kiran,

It is not working for me. I still see it as an ics attachment in my Microsoft outlook. Does anything needs to be changed? Any help is much appreciated.

Regards,
Dedeepya