1
2 create procedure usp_SendMail @ To varchar (100), @ Subject varchar (400) = '', @ Body varchar (8000) =''
3
4AS
5
6 Declare @ object int
7 Declare @ hr int
8
9 EXEC @ hr = sp_OACreate 'cdo. message', @ object OUT
10
11 EXEC @ hr = sp_OASetProperty @ object, 'configuration. fields ("http://schemas.microsoft.com/cdo/configuration/sendusing"). value', '2'
12 EXEC @ hr = sp_OASetProperty @ object, 'configuration. fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver"). value', 'mail .idg-rbi.com.cn'
13
14 -- The following three statements are smtp verification. If the server needs verification, you must modify the user name and password.
15 EXEC @ hr = sp_OASetProperty @ object, 'configuration. fields ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"). value', '1'
16 EXEC @ hr = sp_OASetProperty @ object, 'configuration. fields ("http://schemas.microsoft.com/cdo/configuration/sendusername"). value', 'x @ mail.com'
17 EXEC @ hr = sp_OASetProperty @ object, 'configuration. fields ("http://schemas.microsoft.com/cdo/configuration/sendpassword"). value', 'pass'
18
19 EXEC @ hr = sp_OAMethod @ object, 'configuration. Fields. Update', null
20 EXEC @ hr = sp_OASetProperty @ object, 'to', @
21 EXEC @ hr = sp_OASetProperty @ object, 'bcc ', 'xx @ yahoo.com.cn'
22 EXEC @ hr = sp_OASetProperty @ object, 'from', '<x@mail.com>'
23 EXEC @ hr = sp_OASetProperty @ object, 'subobject', @ Subject
24 EXEC @ hr = sp_OASetProperty @ object, 'bodyformat', 'mailformat. text'
25
26 EXEC @ hr = sp_OASetProperty @ object, 'textbody', @ Body
27
28 SET @ Body = REPLACE (@ Body, CHAR (13), '<br/> ')
29 EXEC @ hr = sp_OASetProperty @ object, 'htmlbody', @ Body
30 EXEC @ hr = sp_OAMethod @ object, 'send', NULL
31
32 -- error Determination
33IF @ hr <> 0
34 BEGIN
35 EXEC sp_OAGetErrorInfo @ object
36 RETURN @ object
37END
38 PRINT 'success'
39 EXEC @ hr = sp_OADestroy @ object
40
41GO