Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 17th, 2008, 01:58 AM
Authorized User
 
Join Date: Sep 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default sending mail from sql server

Hi,
I have created sp
Create Procedure sp_SMTPMail

    @SenderName varchar(100),
    @SenderAddress varchar(100),
    @RecipientName varchar(100),
    @RecipientAddress varchar(100),
    @Subject varchar(200),
    @Body varchar(8000),
    @MailServer varchar(100) = 'localhost'

    AS
    SET nocount on
    declare @oMail int --Object reference
    declare @resultcode int
    EXEC @resultcode = sp_OACreate 'SMTPsvg.Mailer', @oMail OUT
    if @resultcode = 0
    BEGIN
        EXEC @resultcode = sp_OASetProperty @oMail, 'RemoteHost', @mailserver
        EXEC @resultcode = sp_OASetProperty @oMail, 'FromName', @SenderName
        EXEC @resultcode = sp_OASetProperty @oMail, 'FromAddress', @SenderAddress
        EXEC @resultcode = sp_OAMethod @oMail, 'AddRecipient', NULL, @RecipientName, @RecipientAddress
        EXEC @resultcode = sp_OASetProperty @oMail, 'Subject', @Subject
        EXEC @resultcode = sp_OASetProperty @oMail, 'BodyText', @Body
        EXEC @resultcode = sp_OAMethod @oMail, 'SendMail', NULL
        EXEC sp_OADestroy @oMail
    END
    SET nocount off
GO

And trying to execute it
exec sp_SMTPMail @SenderName='Test1', @SenderAddress='[email protected]',
@RecipientName = 'prayadavdeloitte.com', @RecipientAddress = '[email protected]',
@Subject='SQL Test', @Body='Hello, this is a test email from SQL Server'

query is getting executed bt i m nt receiving my mail.
Can any one help me.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending E-Mail from Local to Remote Server tact_259 Classic ASP Basics 6 April 13th, 2008 01:46 AM
sending NULLs into a SQL Server PROC lisabb ASP.NET 2.0 Basics 1 June 21st, 2007 03:36 PM
problem sending values into SQL Server Proc lisabb ASP.NET 2.0 Basics 2 May 23rd, 2007 01:19 PM
problems sending mail with java mail gandacuboy J2EE 2 December 20th, 2006 03:05 PM
Sending both text mail and HTML mail - CDONTS madhukp Classic ASP Basics 1 October 8th, 2003 01:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.