November 30, 2004 at 11:25 am
I have a copy of SP_Send_CDOSysMail I cribbed from the scripts area here. It has been modified to send from a specific user and to use HTML formatting. I run the script from Query Analyzer and it works just fine. I get an HTML formatted email from the correct sender with the correct account. When I execute the SP from an ASP/VBScript page I get no error messages, an RC of 0, but I never get an email.
Can anyone shed a light on this? I'll include a copy of the SP and the ASP code below.
Thanks.
SP ----------------------------------------------------------------------
CREATE PROCEDURE [dbo].[sp_send_cdosysmail]
(
-- @From varchar(100) ,
-- @To varchar(100) ,
@BCC varchar(8000),
@Subject varchar(200)='',
@Body varchar(8000) =''
)
/*********************************************************************
This stored procedure takes the parameters and sends an e-mail.
All the mail configurations are hard-coded in the stored procedure.
Comments are added to the stored procedure where necessary.
References to the CDOSYS objects are at the following MSDN Web site:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_messaging.asp
***********************************************************************/
AS
Declare @iMsg int
Declare @hr int
Declare @rc int
Declare @source varchar(255)
Declare @description varchar(500)
Declare @output varchar(1000)
SET NOCOUNT ON
--************* 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.
EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields(".Value','2'">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.
EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields(".Value'">http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', 'higmx.thehartford.com'
-- Save the configurations to the message object.
EXEC @hr = sp_OAMethod @iMsg, 'Configuration.Fields.Update', null
-- Set the e-mail parameters.
EXEC @hr = sp_OASetProperty @iMsg, 'To', '"The Hartford Today" <'">TheHartfordToday@thehartford.com>'
EXEC @hr = sp_OASetProperty @iMsg, 'From', '"The Hartford Today" <'">TheHartfordToday@thehartford.com>'
EXEC @hr = sp_OASetProperty @iMsg, 'BCC', @BCC
EXEC @hr = sp_OASetProperty @iMsg, 'Subject', @Subject
-- If you are using HTML e-mail, use 'HTMLBody' instead of 'TextBody'.
EXEC @hr = sp_OASetProperty @iMsg, 'HTMLBody', @Body
EXEC @hr = sp_OAMethod @iMsg, 'Send', NULL
SET @rc = @hr
-- Sample error handling.
IF @rc <>0 BEGIN
EXEC @hr = sp_OADestroy @iMsg
RETURN @rc
END
EXEC @hr = sp_OADestroy @iMsg
RETURN 0
GO
ASP ---------------------------------------------------------------
November 30, 2004 at 11:59 am
The problem comes from ASP :
every Constants must be converted to their respective value.
ex : cmdStoredProc2.CommandType = adcmdStoredProc
== : cmdStoredProc2.CommandType = 4
this should solve your problem. If that still doesn't work then you may have a permission issue between the asp user and the SP.
November 30, 2004 at 12:10 pm
cmdStoredProc2.CommandType = adcmdStoredProc works just fine assuming you include adovbs.inc.
It was the damned SQL permissions. The DBA didn't set up the userid the way I'd asked. Once I got the permissions right the SP worked like a charm.
One of those things that's right in front of you but you can't see it because you're too close.
Thanks for the help.
November 30, 2004 at 12:26 pm
Happy to help... how do you include the adovbs.inc file exactly? I haven't worked for a while in asp but I could surely use that info eventually...
November 30, 2004 at 12:31 pm
<!--- #include file="..path/adovbs.inc" -->
"..path/" is the path to the file. If the file is in the same directory as your ASP page you don't need the path info.
Thanks again for your help.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply