日期:2014-05-17 浏览次数:20491 次
use msdb
GO
DECLARE @mailitemid INT
EXEC sp_send_dbmail --调用SQL2005的邮件发送的存储过程。
@profile_name = 'mail_first', --邮件配置文件名。--调用发送邮件的存储过程,登录帐号必须有msdb的datamail权限
@recipients ='wangyunliang@yuantel.com',--用来接受邮件的地址
@subject = '标题',
@body = 'Hello,world',
@body_format='text' ,
@file_attachments ='', --附件
@mailitem_id = @mailitemid OUTPUT
SELECT @mailitemid --取得@mailitemid
WAITFOR DELAY '00:00:05' --等5秒后看结果
SELECT
er.log_id AS [LogID],
er.event_type AS [EventType],
er.log_date AS [LogDate],
er.description AS [Description],
er.process_id AS [ProcessID],
er.mailitem_id AS [MailItemID],
er.account_id AS [AccountID],
er.last_mod_date AS [LastModifiedDate],
er.last_mod_user AS [LastModifiedUser]
FROM msdb.dbo.sysmail_event_log er
WHERE mailitem_id = @mailitemid
ORDER BY [LogDate] DESC