You must Sign In to post a response.
  • Category: SQL Server

    stored proc in sql server to send mail.

    I have written stored procedure for sending mail from sql server.
    But I m getting result code -2147221005 and my mail is not getting send.
    Stored procedure i have written is

    ALTER Procedure [dbo].[sp_SMTPMail]

    @SenderName varchar(100)='Ujwala',
    @SenderAddress varchar(100)='',
    @RecipientName varchar(100)='abc',
    @RecipientAddress varchar(100)='',
    @Subject varchar(200)='hi',
    @Body varchar(8000)='Hi,How r u?',
    @MailServer varchar(100) = 'localhost'


    SET nocount on

    declare @oMail int --Object reference
    declare @resultcode int
    begin try

    -- EXEC @resultcode = sp_OACreate 'SMTPsvg.Mailer', @oMail OUT
    EXEC @resultcode = sp_OACreate 'CDONTS.NewMail', @oMail OUT
    end try
    begin catch

    print ERROR_MESSAGE()

    end catch
    print 'Result Code'
    print @resultCode
    if @resultcode = 0
    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

    SET nocount off

    will anyone pls tell me what that resultcode is realted to.
    Waiting for a favourable reply.
    Thankx and Regards.
  • #294587
    For that you refer this mail they provide in the detail about your error.


    Thanks & Regards
    Patel Vipul

  • #294627
    Thankx for your help.
    I have gone though this link. But the link in the stored proc which r mention r not getting displayed so i not getting the things.
    And i just want to know what the result code -2147221005 is realted to.
    Waiting for reply.
    Thanks and regards,

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.