Create procedure sys_sendmail @ To varchar (100), @ Bcc varchar (500), @ Subject varchar (400) = "", @ Body varchar (4000) = ""
AS Declare @ smtpserver varchar (50) -- SMTP server address Declare @ smtpusername varchar (50) -- SMTP server user name Declare @ smtpuserpassword varchar (50) -- SMTP server password Set @ smtpserver = 'smtp .163.com' Set @ smtpusername = 'yourname @ 163.com '-- set this parameter to your 163 email user name. Set @ smtpuserpassword = 'password' -- set it to your 163 email password. Declare @ object int Declare @ hr int EXEC @ hr = sp_OACreate 'CDO. Message', @ object OUT EXEC @ hr = sp_OASetProperty @ object, 'configuration. fields ("http://schemas.microsoft.com/cdo/configuration/sendusing"). Value', '2' EXEC @ hr = sp_OASetProperty @ object, 'configuration. fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver"). Value', @ smtpserver -- The following three statements are smtp verification. If the server needs verification, you must modify the user name and password. EXEC @ hr = sp_OASetProperty @ object, 'configuration. fields ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"). Value', '1' EXEC @ hr = sp_OASetProperty @ object, 'configuration. fields ("http://schemas.microsoft.com/cdo/configuration/sendusername"). Value', @ smtpusername EXEC @ hr = sp_OASetProperty @ object, 'configuration. fields ("http://schemas.microsoft.com/cdo/configuration/sendpassword"). Value', @ smtpuserpassword EXEC @ hr = sp_OAMethod @ object, 'configuration. Fields. Update', null EXEC @ hr = sp_OASetProperty @ object, 'to', @ EXEC @ hr = sp_OASetProperty @ object, 'bcc ', @ Bcc EXEC @ hr = sp_OASetProperty @ object, 'from', @ smtpusername EXEC @ hr = sp_OASetProperty @ object, 'subobject', @ Subject EXEC @ hr = sp_OASetProperty @ object, 'textbody', @ Body EXEC @ hr = sp_OAMethod @ object, 'send', NULL -- Identify errors IF @ hr <> 0 BEGIN EXEC sp_OAGetErrorInfo @ object Print 'failed' Return @ object END PRINT 'success' EXEC @ hr = sp_OADestroy @ object GO |