"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Saturday, July 31, 2010

sql mail through store procedure in sql server 2005/2008

 Hi friendz,
i already posted Create Account and profile in sql server 2005 and  sent sql mail on trigger in sql server 2005 . 2day I'm showing sending mail through store procedure



code

ALTER PROCEDURE [dbo].[SP_Candidate_ReferAFriend_Email]
    @ToEmail varchar(200),
    @Msg varchar(MAX),
    @Subj varchar(200)
AS
BEGIN
    -- SENDING EMAIL
    BEGIN TRY
    EXEC msdb.dbo.sp_send_dbmail

    @recipients = @ToEmail,
    @body = @Msg,
    @sensitivity ='Personal',   
    @importance ='High',    
    @body_format = 'HTML',
    @subject = @Subj,
    @profile_name = 'Simplyasp'
    END TRY
    BEGIN CATCH
        SELECT
        ERROR_NUMBER() as ErrorNumber,
        ERROR_MESSAGE() as ErrorMessage;
    END CATCH   
END



for easy understanding i had given all parameter friendly name. i hope u can easily understand. :).
Have a nice day... 'N happy Coding :)

 Sex and the City: The Complete Second SeasonSex and the City 2: The Stories. The Fashion. The Adventure.Sex and the City - The Movie (Full Screen Edition)

No comments: