Database Mail Issue

  • Hi,

    I have created a trigger to generate a mail as shown below.

    The MessageBody field in the table contains the HTML & its datatype is TEXT.

    The issue is that the mail is getting generated, but rather than getting the html page in the mail . I am getting the source code of the html.

    When I include @body_format = 'HTML'; in msdb.dbo.sp_send_dbmail, I get a blank mail. What could be the issue

    ALTER TRIGGER ExceptionMail

    ON DistributionList

    FOR INSERT

    AS

    DECLARE @Mail bigint;

    SET @Mail=(SELECT Mail_Id FROM inserted)

    DECLARE @html NVARCHAR(MAX);

    --SET @Message2=(SELECT EVENTDATA().value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]', 'nvarchar(max)'))

    SET @html=(SELECT CONVERT(NVARCHAR(MAX),MessageBody)

    FROM MailBackup

    WHERE MailId=@Mail)

    IF (SELECT COUNT(*) FROM inserted WHERE Current_Status = 3) = 1

    BEGIN

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'Admin',

    @recipients = 'nithin@mystifly.com',

    @subject = 'Exception Mail ',

    @body = @html;

    END

    GO

  • Add the following to your e-mail script:

    @body_format = 'HTML'

    So it should look like this:

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'Admin',

    @recipients = 'nithin@mystifly.com',

    @subject = 'Exception Mail ',

    @body_format = 'HTML',

    @body = @html;

  • Thank You :-):-):-):-):-):-) !!! Its working now :-):-):-):-):-)

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply