Click here to Skip to main content
15,915,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to send email from my database to email address in trigger
by mean after updating specific column in table i want email sent to some body but i need this happen from sql server i need it urgent
please i need any help
with regards
Posted

CREATE PROCEDURE dbo.mailsnd AS 
BEGIN 
    SET NOCOUNT ON 
    -- do some other actions 
    DECLARE @body VARCHAR(1024) 
    SET @body = 'foo was fired '+ 
        CONVERT(VARCHAR, GETDATE()) 
 
    EXEC master..xp_sendmail 
        @recipients='you@you.com', 
        @message = @body, 
        @subject = 'mail was fired.' 
END 
 
-- or you can do it conditionally: 
 
CREATE PROCEDURE dbo.mailsnd AS 
BEGIN 
    SET NOCOUNT ON 
    -- do some other action 
    IF @@ROWCOUNT > 0 
    BEGIN 
        DECLARE @body VARCHAR(1024) 
        SET @body = 'foo was fired ' + 
            CONVERT(VARCHAR, GETDATE()) + 
            CHAR(13) + CHAR(10) +  
            CONVERT(VARCHAR, @@ROWCOUNT) 
 
        EXEC master..xp_sendmail 
            @recipients='you@you.com', 
            @message = @body, 
            @subject = 'mail was fired.' 
    END 
END
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900