SQL Server
SQL Server
Add an iCalendar Meeting Invitation to an Email
See more Email Object Examples
Demonstrates the Chilkat Email.AddiCalendarAlternativeBody method, which adds or replaces an iCalendar body as a text/calendar alternative. The first argument is the iCalendar content and the second is the iCalendar method (such as REQUEST, REPLY, or CANCEL). If an iCalendar alternative already exists it is replaced, so repeated calls leave at most one. This example attaches a simple meeting request.
Background: When you receive a calendar invite that your mail client shows with Accept/Decline buttons, it arrives as an iCalendar (
.ics) body carried in the message as a text/calendar alternative. The METHOD — REQUEST to invite, CANCEL to withdraw, REPLY to respond — tells the recipient's client how to treat it. Delivering it as an alternative means clients that understand calendars show the invite UI, while others fall back to the plain-text or HTML body.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Demonstrates the AddiCalendarAlternativeBody method, which adds (or replaces) an
-- iCalendar body as a text/calendar alternative. The first argument is the iCalendar content and the second
-- is the iCalendar method (such as REQUEST, REPLY, or CANCEL).
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @email, 'Subject', 'Meeting invitation'
EXEC sp_OAMethod @email, 'SetTextBody', NULL, 'You are invited to the Project Sync meeting.', 'text/plain'
-- The iCalendar (VCALENDAR) content. In practice this is generated iCalendar text.
DECLARE @ical nvarchar(4000)
SELECT @ical = 'BEGIN:VCALENDAR' + CHAR(13) + CHAR(10) + 'VERSION:2.0' + CHAR(13) + CHAR(10) + 'METHOD:REQUEST' + CHAR(13) + CHAR(10) + 'BEGIN:VEVENT' + CHAR(13) + CHAR(10) + 'SUMMARY:Project Sync' + CHAR(13) + CHAR(10) + 'DTSTART:20260720T160000Z' + CHAR(13) + CHAR(10) + 'DTEND:20260720T163000Z' + CHAR(13) + CHAR(10) + 'END:VEVENT' + CHAR(13) + CHAR(10) + 'END:VCALENDAR' + CHAR(13) + CHAR(10)
-- Add the iCalendar as a text/calendar alternative using the REQUEST method.
DECLARE @success int
EXEC sp_OAMethod @email, 'AddiCalendarAlternativeBody', @success OUT, @ical, 'REQUEST'
EXEC sp_OAGetProperty @email, 'NumAlternatives', @iTmp0 OUT
PRINT 'NumAlternatives = ' + @iTmp0
EXEC @hr = sp_OADestroy @email
END
GO