Send Meeting Invite Calendar Email From Apex
Sample Code:
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); //Set To Addresss mail.setToAddresses(new List<String>{'itzbiswajeet@gmail.com'}); //Set Email Subject mail.setSubject('Test Meeting Invitation'); //Set Email Body mail.setPlainTextBody('Test Meeting'); //Meeting Start Time & End Time DateTime dt = DateTime.now().addDays(5); //Start Date String startDT = String.valueof(dt.year() +'0'+ dt.month() +''+ dt.day() + 'T010000Z'); //End Date String endDT = String.valueof(dt.year() +'0'+ dt.month() +''+ dt.day() + 'T020000Z'); //Create Meeting Body String meetingInviteBody = ''; meetingInviteBody += 'BEGIN:VCALENDAR\n'; meetingInviteBody += 'PRODID::-//hacksw/handcal//NONSGML v1.0//EN\n'; meetingInviteBody += 'VERSION:2.0\n'; meetingInviteBody += 'METHOD:PUBLISH\n'; meetingInviteBody += 'X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n'; meetingInviteBody += 'BEGIN:VEVENT\n'; meetingInviteBody += 'CLASS:PUBLIC\n'; meetingInviteBody += 'CREATED:20150126T203709Z\n'; meetingInviteBody += 'DTEND:'+endDT+'\n'; meetingInviteBody += 'DTSTAMP:20150126T203709Z\n'; meetingInviteBody += 'DTSTART:'+startDT+'\n'; meetingInviteBody += 'LAST-MODIFIED:20150126T203709Z\n'; meetingInviteBody += 'LOCATION:USA\n'; meetingInviteBody += 'PRIORITY:5\n'; meetingInviteBody += 'SEQUENCE:0\n'; meetingInviteBody += 'SUMMARY:Test Meeting\n'; meetingInviteBody += 'LANGUAGE=en-us:Meeting\n'; meetingInviteBody += 'TRANSP:OPAQUE\n'; meetingInviteBody += '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'; meetingInviteBody += 'X-MICROSOFT-CDO-BUSYSTATUS:BUSY\n'; meetingInviteBody += 'X-MICROSOFT-CDO-IMPORTANCE:1\n'; meetingInviteBody += 'END:VEVENT\n'; meetingInviteBody += 'END:VCALENDAR'; //Meeting Email Attachment Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment(); attach.Filename = 'meeting.ics'; attach.ContentType = 'text/calendar'; attach.Inline = true; attach.Body = Blob.valueOf(meetingInviteBody); //Attach Meeting Attachment mail.setFileAttachments(new Messaging.EmailFileAttachment[] {attach}); //Send Email Messaging.SendEmailResult[] er = Messaging.sendEmail(new Messaging.Email[] { mail });