|
-
Jan 23rd, 2003, 08:25 AM
#1
Thread Starter
New Member
CDO from Stored Procedures
Right this is one for the real hardcore! I have managed to send an SMTP mail using CDO in a stored procedure. However I now want to add an HTML body for the message using the method .CreateMHTML ... Every way I try and do this I get errors and no message! Can anyone help!!!?!!!
-
Jan 23rd, 2003, 08:40 AM
#2
Frenzied Member
What code have you got to create the message?
How do you create the body at present?
What have you tried?
-
Jan 23rd, 2003, 08:42 AM
#3
Thread Starter
New Member
Declare @iMsg int
Declare @hr int
Declare @source varchar(255)
Declare @description varchar(500)
Declare @output varchar(1000)
Declare @Body varchar(8000)
--************* Create the CDO.Message Object ************************
EXEC @hr = sp_OACreate 'CDO.Message', @iMsg OUT
--***************Configuring the Message Object ******************
-- This is to configure a remote SMTP server.
-- http://msdn.microsoft.com/library/de..._sendusing.asp
EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'
-- This is to configure the Server Name or IP address.
-- Replace MailServerName by the name or IP of your SMTP Server. 195.153.50.96
EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', 'smtpserver'
print @hr
-- Save the configurations to the message object.
EXEC @hr = sp_OAMethod @iMsg, 'Configuration.Fields.Update', null
print @hr
-- Set the e-mail parameters.
EXEC @hr = sp_OASetProperty @iMsg, 'To', '[email protected]'
EXEC @hr = sp_OASetProperty @iMsg, 'From', '[email protected]'
EXEC @hr = sp_OASetProperty @iMsg, 'Subject', 'TEST EMAIL'
print @hr
-- If you are using HTML e-mail, use 'HTMLBody' instead of 'TextBody'.
EXEC @hr = sp_OAMethod @iMsg, 'CreateMHTMLBody' , 'http://www.yahoo.com'
declare @src varchar(1000), @desc varchar(1000)
If @hr <> 0
Begin
EXEC sp_OAGetErrorInfo @iMsg, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
End
EXEC @hr = sp_OAMethod @iMsg, 'Send', NULL
If @hr <> 0
Begin
EXEC sp_OAGetErrorInfo @iMsg, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
End
IF @hr = 0 BEGIN
PRINT 'Message Delivered'
END
-- Sample error handling.
IF @hr <>0
select @hr
BEGIN
EXEC @hr = sp_OAGetErrorInfo NULL, @source OUT, @description OUT
IF @hr = 0
BEGIN
SELECT @output = ' Source: ' + @source
PRINT @output
SELECT @output = ' Description: ' + @description
PRINT @output
END
ELSE
BEGIN
PRINT ' sp_OAGetErrorInfo failed.'
RETURN
END
END
-- Do some error handling after each step if you need to.
-- Clean up the objects created.
EXEC @hr = sp_OADestroy @iMsg
-
Jan 23rd, 2003, 08:43 AM
#4
Thread Starter
New Member
Above is the code of my SP. It returns some kind of error telling me about the usage of the method call. Even though the code looks correct?!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|