Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 can't send mail from S Proc to remote smtp server

Author  Topic 

london24
Starting Member

2 Posts

Posted - 2009-06-02 : 04:12:42
Hi

When I execute this stored procedure, the message still gets sent from my own server (windows server 2003 standard edition) but I want it sent from an external smtp server that I have permission to use and successfully use via asp.net pages. Can anyone see what I am doing wrong? Thanks for any help.

CREATE PROCEDURE spAutoEmail

AS

declare @Text varchar(400)
declare @i Integer
declare @Subject varchar(100)

set @Text = 'Hello'

set @Subject = 'Hello'

SET NOCOUNT ON

DECLARE @MailObject INT
DECLARE @ReturnCode INT

EXEC @ReturnCode = sp_OACreate 'CDO.Message', @MailObject OUT

IF @ReturnCode = 0

BEGIN

EXEC @ReturnCode = sp_OASetProperty @MailObject, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'
EXEC @ReturnCode = sp_OASetProperty @MailObject, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', 'smtp.blueyonder.co.uk'
EXEC @ReturnCode = sp_OASetProperty @MailObject ,'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusername").Value', 'removed'
EXEC @ReturnCode = sp_OASetProperty @MailObject,'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendpassword").Value', 'removed'

EXEC @ReturnCode = sp_OASetProperty @MailObject, 'To', @To
EXEC @ReturnCode = sp_OASetProperty @MailObject, 'From', 'removed'
EXEC @ReturnCode = sp_OASetProperty @MailObject, 'Subject', @Subject
EXEC @ReturnCode = sp_OASetProperty @MailObject, 'TextBody', @Text
EXEC @ReturnCode = sp_OAMethod @MailObject, 'Send', NULL

END

EXEC sp_OADestroy @MailObject
GO
   

- Advertisement -