• MURALIKRISHNA ARIKOLA
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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);
    }
}