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 2008 Forums
 Transact-SQL (2008)
 cannot send mail from stored proc via remote smtp

Author  Topic 

london24
Starting Member

2 Posts

Posted - 2009-05-30 : 17:50:29
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

eralper
Yak Posting Veteran

66 Posts

Posted - 2009-06-08 : 09:39:53
Hello London,

I googled some and found an article at MS Support at [url]http://support.microsoft.com/default.aspx/kb/312839[/url] pointing the necessity for configuring smart host.

Perhaps it is related with your situation,



-------------
Eralper
http://www.kodyaz.com
Go to Top of Page
   

- Advertisement -