Sp_send_Dbmail Image Issue

  • Hi,

    i want to show Images in my mails, i am using sp_send_dbMail in HTML mode. is there any way that i can show Images in my mails.

  • yes you can show images in your HTML emails. Do you want to post the code you have so far. Is the SP failing to execute or are you just getting the mail without the image?

    edited to add test code i used a while back which worked fine

    DECLARE @HTML NVARCHAR(MAX) ;

    SET @HTML =

    ' '+

    ' ' +

    ' ' +

    ' ' +

    ' ' +

    '

    ' +

    '

    ' +

    ' ' +

    ' ' +

    ' ' + ' ' +

    CAST ( ( select emailaddy from EmailTest where id = @count)

    AS NVARCHAR(MAX));

    EXEC msdb.dbo.sp_send_dbmail @recipients=@rec,

    @subject = 'Test HTML Email from SQL',

    @body = @HTML,

    @body_format = 'HTML' ;

  • rar!! can someone tell me how to post HTML code without it removing all the tags...please? 🙂

  • Hi,

    Thanks for the Reply, here exactly mode code is,

    my question is that in my Query lets say i have as Follow:

    CAST(( Select td=[Name],'' from abc Xml path('tr') ......

    lets say here i also have a column name Image so i want to show indicator based on the condition where i can show status kind of thing....lets say above Query Result would be like:

    XYZ RED

    ABC YELLOW

    kind of, is this possible,

    Thanks

    Parth

  • im not 100% sure if you can do that kind of thing in HTML code or not. From what i can tell you are trying to return some kind of traffic light indicator based on what the query result is?

    If i were you i would declare a variable, and then run a standard tsql query to determine whether it should be red/yellow/green, then use a case/if statement to produce your email, ie...

    declare @ind varchar(10)

    set @ind = (select case ColumnName when xxx then 'Green' when yyy then 'Yellow' else Red End)

    if @ind = 'Green'

    -- put email code here and set the font/background to green, however you want it to show

    if @ind = 'Yellow'

    -- put email code here and set the font/background to yellow

    if @ind = 'Red'

    -- put email code here and set the font/background to red

    would that do the job?

  • i have already tried it and it is working fine but my Que. is i want to show images like

    on condition basis like below:

    td=case when some thing then <img ....... else something end ,'' ,

    this kind of thing , and i have tried this also but with no luch rather it is taking this thing as Text and shows me the Text in case statement.

    Thanks anyways

    Parth

  • I dont believe you can do a case statement within HTML. If you cant implement the solution i mentioned in my last post it might be possible to end your HTML string, do you Case statement as part of the tsql command and then continue your HTML tags afterwards. This will work the same way as inserting a value from a sql query into your HTML code. Unfortunately i still havent worked out how to post HTML so i cant post any example code right now.

  • SEND ME MAIL ON parth83.rawal@gmail.com,

    though i am already having html code but issue only is not able to put image in my HTML.

  • parth83.rawal (3/16/2009)


    SEND ME MAIL ON parth83.rawal@gmail.com,

    though i am already having html code but issue only is not able to put image in my HTML.

    Just emailed you, let me know if you dont get it

  • Animal, I have the same issue, can you email me the solution you posted at jonesbilly0@gmail.com. Thanks in advance.

  • Hi,

    Sorry to bother you, but what i can say is you need to create HTML with Cursor,

    Let say,

    Fetch Next from C1 into @tr,@td

    --In this @tr,@td you have to plot your image

    @TD=Some value

    @TD=you Image code , it could be Case statement....

    Fetch next from C1

    This should help.

Viewing 11 posts - 1 through 10 (of 10 total)

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