This is a discussion on Unable to create object error in sp_SendSMTPMail within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello, I am attempting to send emails using T-SQL (in a SQLServerAgent Job) using the stored procedure sp_SendSMTPMail. I ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello, I am attempting to send emails using T-SQL (in a SQLServerAgent Job) using the stored procedure sp_SendSMTPMail. I created the stored proc using the following script that I got off a post here on google. CREATE PROCEDURE sp_SendSMTPMail (@From varchar(255), @To varchar(8000), @Subject varchar(255), @Body varchar(8000), @cc varchar(8000) = NULL, @Bcc varchar(8000) = NULL) AS DECLARE @newmail int DECLARE @result int -- Create the CDONTS.Newmail object EXEC @result = sp_OACreate 'CDONTS.NewMail', @newmail OUT IF @result <> 0 BEGIN PRINT 'Error creating object' EXEC sp_displayoaerrorinfo @newmail, @result RETURN END -- Check the Optional Properties IF not @cc = NULL BEGIN EXEC @result = sp_OASetProperty @newmail, 'cc', @cc IF @result <> 0 BEGIN PRINT 'Error setting [cc] property' -- EXEC sp_displayoaerrorinfo @newmail, @result RETURN END END IF not @Bcc = NULL BEGIN EXEC @result = sp_OASetProperty @newmail, 'Bcc', @Bcc IF @result <> 0 BEGIN PRINT 'Error setting [Bcc] property' -- EXEC sp_displayoaerrorinfo @newmail, @result RETURN END END --set the non-optional properties EXEC @result = sp_OASetProperty @newmail, 'From', @From EXEC @result = sp_OASetProperty @newmail, 'To', @To EXEC @result = sp_OASetProperty @newmail, 'Subject', @Subject EXEC @result = sp_OASetProperty @newmail, 'Body', @Body -- Send the message... EXEC @result = sp_OAMethod @newmail, 'Send' IF @result <> 0 BEGIN PRINT 'Error sending message' -- EXEC sp_displayoaerrorinfo @newmail, @result RETURN END -- Destroy the object. EXEC @result = sp_OADestroy @newmail IF @result <> 0 BEGIN PRINT'Error destroying object' -- EXEC sp_displayoaerrorinfo @newmail, @result RETURN END GO ______________________________________________ This worked perfectly in testing at our office but when we shipped to the client it produced the error 'Error creating object'. We sent the client the script to create the sp_displayoaerrorinfo proc and got the following error message. Error creating object-2147221005 OLE Automation Error Information HRESULT: 0x800401f3 Source: ODSOLE Extended Procedure Description: Invalid class string Now this suggested to me that the for some reason we were unable to reference the CDO library, or it wasn't installed. However they have Outlook 2000 installed with CDO installed with it. I've had had them remove and reinstall the CDO library but that hasn't helped. Other thing I though of was a permission type problem. They are using NT authentication for there logins into SQL server and are logged on the server as Administrator who I would assume has all required permissions. Any suggestions for either determining the cause of them problems or a solution? Thanks in advance. Bob. |
| |||
| Hi You may want to look at: http://www.sqldev.net/xp/xpsmtp.htm John "Robert Hogan" <busrhogan@hotmail.com> wrote in message news:eb62f112.0409021753.5170d92@posting.google.co m... > Hello, > > I am attempting to send emails using T-SQL (in a SQLServerAgent Job) > using the stored procedure sp_SendSMTPMail. I created the stored proc > using the following script that I got off a post here on google. > > CREATE PROCEDURE sp_SendSMTPMail (@From varchar(255), > @To varchar(8000), > @Subject varchar(255), > @Body varchar(8000), > @cc varchar(8000) = NULL, > @Bcc varchar(8000) = NULL) > AS > > DECLARE @newmail int > DECLARE @result int > > -- Create the CDONTS.Newmail object > EXEC @result = sp_OACreate 'CDONTS.NewMail', @newmail OUT > IF @result <> 0 > BEGIN > PRINT 'Error creating object' > EXEC sp_displayoaerrorinfo @newmail, @result > RETURN > END > > -- Check the Optional Properties > IF not @cc = NULL > BEGIN > EXEC @result = sp_OASetProperty @newmail, 'cc', @cc > IF @result <> 0 > BEGIN > PRINT 'Error setting [cc] property' > -- EXEC sp_displayoaerrorinfo @newmail, @result > RETURN > END > END > IF not @Bcc = NULL > BEGIN > EXEC @result = sp_OASetProperty @newmail, 'Bcc', @Bcc > IF @result <> 0 > BEGIN > PRINT 'Error setting [Bcc] property' > -- EXEC sp_displayoaerrorinfo @newmail, @result > RETURN > END > END > > --set the non-optional properties > EXEC @result = sp_OASetProperty @newmail, 'From', @From > EXEC @result = sp_OASetProperty @newmail, 'To', @To > EXEC @result = sp_OASetProperty @newmail, 'Subject', @Subject > EXEC @result = sp_OASetProperty @newmail, 'Body', @Body > > -- Send the message... > EXEC @result = sp_OAMethod @newmail, 'Send' > IF @result <> 0 > BEGIN > PRINT 'Error sending message' > -- EXEC sp_displayoaerrorinfo @newmail, @result > RETURN > END > > -- Destroy the object. > EXEC @result = sp_OADestroy @newmail > IF @result <> 0 > BEGIN > PRINT'Error destroying object' > -- EXEC sp_displayoaerrorinfo @newmail, @result > RETURN > END > > GO > > ______________________________________________ > This worked perfectly in testing at our office but when we shipped to > the client it produced the error 'Error creating object'. We sent the > client the script to create the sp_displayoaerrorinfo proc and got the > following error message. > > Error creating object-2147221005 > OLE Automation Error Information > HRESULT: 0x800401f3 > Source: ODSOLE Extended Procedure > Description: Invalid class string > > > Now this suggested to me that the for some reason we were unable to > reference the CDO library, or it wasn't installed. However they have > Outlook 2000 installed with CDO installed with it. I've had had them > remove and reinstall the CDO library but that hasn't helped. > > Other thing I though of was a permission type problem. They are using > NT authentication for there logins into SQL server and are logged on > the server as Administrator who I would assume has all required > permissions. > > Any suggestions for either determining the cause of them problems or a > solution? > > Thanks in advance. > > Bob. |
| |||
| "John Bell" <jbellnewsposts@hotmail.com> wrote in message news:<4138e3a6$0$26142$afc38c87@news.easynet.co.uk >... > Hi > > You may want to look at: > http://www.sqldev.net/xp/xpsmtp.htm > > John > The client is using Exchange Server, the dll you have referenced using SMTP to send the messages - will these work together? I have made some progress on sorting out the original problem. I registered two CDO Dll's that documentation lead me to believe were needed (CDOSYS.DLL and CDO.DLL I think off the top of my head) and the create object error went away. However I'm now getting an error when attempting to send the message. I think the problem is with the installation of CDO, sadly the client has 'lost' the CD used to install Office 2000 on that server and will have to acquire another - but can't wait that long for a solution so I will have to look at a third party solution I suspect. I have used JMail before but this didn't seem to work when I tried it here, again this uses SMTP and I'm not sure that Exchange Server will (by default) provide an SMTP mail server? Any help very much apprecitated. |
| ||||
| Hi I have only just found this reply! Have you figured out what was wrong? If you are using your exchange server to send/receive external emails then you should have the SMTP connector configured. John busrhogan@hotmail.com (Robert Hogan) wrote in message news:<eb62f112.0409061904.371ab76@posting.google.c om>... > "John Bell" <jbellnewsposts@hotmail.com> wrote in message news:<4138e3a6$0$26142$afc38c87@news.easynet.co.uk >... > > Hi > > > > You may want to look at: > > http://www.sqldev.net/xp/xpsmtp.htm > > > > John > > > > The client is using Exchange Server, the dll you have referenced using > SMTP to send the messages - will these work together? > > I have made some progress on sorting out the original problem. I > registered two CDO Dll's that documentation lead me to believe were > needed (CDOSYS.DLL and CDO.DLL I think off the top of my head) and the > create object error went away. However I'm now getting an error when > attempting to send the message. I think the problem is with the > installation of CDO, sadly the client has 'lost' the CD used to > install Office 2000 on that server and will have to acquire another - > but can't wait that long for a solution so I will have to look at a > third party solution I suspect. > > I have used JMail before but this didn't seem to work when I tried it > here, again this uses SMTP and I'm not sure that Exchange Server will > (by default) provide an SMTP mail server? > > Any help very much apprecitated. |