Embedd Image from databse mail

  • Hi

    I want to send an image in mail body from database mail

    Declare @html_docy nvarchar(max) =

    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <title></title>

    </head>

    <body>

    <div id="Maincontainer">

    <div id="EmailContent">

    <div>

    <img src="logo.png" width="235" height="70" border="0" alt=""/>

    <hr />

    </div>

    <div style="padding-top: 20px">

    <span style="font-size: 10pt; margin-bottom: 0.0001pt; font-family: arial,helvetica,sans-serif;"></body>'

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name='my_profile',

    @file_attachments = 'c:\logo.png',

    @recipients='xyz@gmail.com',

    @subject = 'Tests',

    @body = @html_docy,

    @body_format = 'HTML'

    here i could not see image in mail body..in attachment i can see??

    can any one help me with this??

    please find attachment

  • it's not obvious, but if you look at the html source of some of your own email, the trick is referencing the content id(cid) of the attachment(s) that was included; by using the cid:, you'll get the image inline, butdepending on the email program (i.e. Thunderbird), the image may still be prevented from showing at all, without an explicit user selection.

    <img src="cid:logo.png" width="235" height="70" border="0" alt=""/>

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • $t@r (11/7/2013)


    Hi

    I want to send an edited image[/url] in mail body from database mail

    here i could not see image[/url] in mail body..in attachment i can see??

    can any one help me with this??

    please find attachment

    :-)Attach required images using @file_attachments separate them using ; an then use their names (only file name with extension) in @body.

    more at:

    http://stackoverflow.com/questions/8833880/how-can-we-encode-the-image-into-the-body-of-the-email-when-sending-mail-using-d

    or may be you can have a look at:

    http://www.sqlservercentral.com/Forums/Topic1292947-391-1.aspx

  • actually, using the content id (cid:) is the right way.

    by leaving it out, you are just taking advantage of some email clients smart features of filling in missing tags, the same way all clients will automatically insert a missing/implied </td> tag.

    so doing it that way , you'll eventually get someone who says they don't see the images, and it'll be because their spcific email client didn't re-vamp the html to fix the mistake.

    in this post here, i provided a complete coded example for sp_send_dbmail

    http://www.sqlservercentral.com/Forums/FindPost941817.aspx

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Lowell (1/17/2014)


    actually, using the content id (cid:) is the right way.

    by leaving it out, you are just taking advantage of some email clients smart features of filling in missing tags, the same way all clients will automatically insert a missing/implied </td> tag.

    so doing it that way , you'll eventually get someone who says they don't see the images, and it'll be because their spcific email client didn't re-vamp the html to fix the mistake.

    in this post here, i provided a complete coded example for sp_send_dbmail

    http://www.sqlservercentral.com/Forums/FindPost941817.aspx

    THAT would make a great "SQL Spackle" article, Lowell. You should write it up and submit it.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 4 (of 4 total)

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