http://social.microsoft.com/Forums/it-IT/3ba417d6-6548-48ed-9e9f-1a6549edc569
大家好,
在此提供一个示例展示如何使用数据库邮件发送会议邀请。
创建CLR 存储过程,用来生成.ics文件:
1. 在
Visual Studio中,创建一个Visual C# SQL CLR Database Project,请看:
2. 添加一个数据库引用,请看:
[Microsoft.SqlServer.Server.SqlProcedure] public static void CLROutlook(string MeetingLocation,string MeetingSubject,string MeetingDescription,DateTime BeginDate,DateTime EndDate) { // Put your code here String[] contents = { "BEGIN:VCALENDAR", "PRODID:-//Flo Inc.//FloSoft//EN", "BEGIN:VEVENT", "DTSTART:" + BeginDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"), "DTEND:" + EndDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"), "LOCATION:" + MeetingLocation, "DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + MeetingDescription, "SUMMARY:" + MeetingSubject, "PRIORITY:3", "END:VEVENT", "END:VCALENDAR" }; System.IO.File.WriteAllLines(@"E:\Meeting\OutLookMeeting.ics", contents); }
5. 我们也可以使用T-SQL 语句来注册该程序集,请参阅下面的语句:
--Set the database to TRUSTWORTHY mode ALTER DATABASE Test SET TRUSTWORTHY ON; GO CREATE ASSEMBLY CLROutLook FROM ‘E:\CLR\OutLook\CLROutLook\CLROutLook\bin\Debug\CLROutLook.dll‘ WITH PERMISSION_SET = UNSAFE
6. 创建存储过程,请参阅下面的语句:
CREATE PROCEDURE [dbo].[CLROutlook] @MeetingLocation [nvarchar](4000), @MeetingSubject [nvarchar](4000), @MeetingDescription [nvarchar](4000), @BeginDate [datetime], @EndDate [datetime] WITH EXECUTE AS CALLER AS EXTERNAL NAME [CLROutLook].[StoredProcedures].[CLROutlook] GO
配置数据邮件:
1. 配置文件和邮件账号:
--create a .ics file DECLARE @MeetingLocation NVARCHAR(50) DECLARE @MeetingSubject NVARCHAR(50) DECLARE @MeetingDescription NVARCHAR(500) DECLARE @BeginDate DATETIME DECLARE @EndDate DATETIME SET @MeetingLocation=‘3106‘ SET @MeetingSubject=‘SQL Replication Training‘ SET @MeetingDescription=‘Replication is a set of technologies for copying and distributing data and database objects from one database to another and then synchronizing between databases to maintain consistency‘ SET @BeginDate=‘2010-12-25 10:00:000‘ SET @EndDate=‘2010-12-25 11:00:000‘ EXEC dbo.CLROutlook @MeetingLocation,@MeetingSubject,@MeetingDescription,@BeginDate,@EndDate GO --Send Email EXEC msdb.dbo.sp_send_dbmail @profile_name = ‘TestProfile‘, @recipients = ‘Test@example.com‘, @subject = ‘SQL Replication Training invitation‘, @file_attachments=‘E:\Meeting\OutLookMeeting.ics‘
谢谢。
原文地址:http://www.cnblogs.com/netact/p/3772561.html