can you use msdb.dbo.sp_send_dbmail to set up calendar appointments?

Posted on

Question :

For example, in health care, every employee gets a PPD test (they jab your arm with something) and you have to go back in 48 hours to see if you’ve sprouted an extra head.

Everybody forgets.

The nurses document in their EHR that they jabbed the patient, and I can send out an email reminding the employee to go check for their extra head, but I’d rather make it a calendar invite.


How would you set up an outlook calendar appointment from SQL Server?

Answer :

(I dont have outlook to test it .. so the code is not tested by me)

Borrowed from : Send Outlook Calendar Requests in Email

EXEC msdb.dbo.sp_send_dbmail    
  @recipients ='<your email address>'    
  ,@subject = 'iCalendar Example'    
  , @query = 'SET NOCOUNT ON;SELECT ''BEGIN:VCALENDAR''+ CHAR(13)+ ''VERSION:2.0''+ CHAR(13)+ ''METHOD:PUBLISH''+ CHAR(13)+ ''BEGIN:VEVENT''+ CHAR(13)+ ''CLASS:PUBLIC''+ CHAR(13)+ ''DESCRIPTION:This is the iCalendar example Most client application support it''+ CHAR(13)+ ''SUMMARY:iCalendar''+ CHAR(13)+ ''DTEND:20150325T110000''+ CHAR(13)+ ''DTSTART:20150325T120000''+ CHAR(13)+ ''LOCATION:My Office''+ CHAR(13)+ ''END:VEVENT''+ CHAR(13)+ ''END:VCALENDAR'''   
  , @attach_query_result_as_file = 1   
  , @query_result_header = 0   
  , @query_result_separator = 'CHAR(10)+CHAR(13)'   
  , @exclude_query_output = 1   
  , @query_attachment_filename = '123.ics'  

I’ve recently developed an open-source solution in CLR for sending calendar invitations (ical / ics) from within SQL Server.

This works:

Leave a Reply

Your email address will not be published. Required fields are marked *