1

I want to embed an image into an HTML email with SQL server. The emails are getting sent but the images do not show. My code is as follows:

    DECLARE @body_custom VARCHAR(MAX)
SET @body_custom = '<head>
                        <title> Embedded Logo Example</title>
                        <meta name="Generator" content="EditPlus">
                        <meta name="Author" content="">
                        <meta name="Keywords" content="">
                        <meta name="Description" content="">
                    </head>
                    <body>
                        <table>
                            <tr>
                                <td valign="top" align="left">MyHeader</td>
                            </tr>
                            <tr>
                                <td valign="top" align="left">
                                    <img src="image_1.jpg" width="235" height="70" alt="">
                                </td>
                                <tr>
                                <td valign="top" align="left">
                                    <img src="image_2.png" width="235" height="70" alt="">
                                </td>
                            </tr>
                            <tr>
                                <td valign="top" align="left">
                                    <img src="image_3.gif" width="235" height="70" alt="">
                                </td>
                            </tr>
                            </tr>
                        </table>
                    </body>'
EXEC msdb.dbo.sp_send_dbmail 
    @profile_name = 'Google_Gmail_Account'
    , @recipients = '???@gmail.com'
    , @subject = 'SQl 2008 R2 Email Test'
    , @body = @body_custom
    , @body_format = 'HTML'
    , @file_attachments = 'C:\Users\User\Desktop\image_1.jpg;C:\Users\User\Desktop\image_2.png;C:\Users\User\Desktop\image_3.gif'

This sends the email and the images as attachments, but they do not display in the email.

I have also added the images to my google drive and taken their links and used that, but still no success...

Astora
  • 55
  • 2
  • 5
  • I don't have time to test it but you should be able to use `cid:` syntax as pointed out in this thread: http://www.sqlservercentral.com/Forums/Topic941321-391-1.aspx – Chris Haas May 04 '15 at 21:43

1 Answers1

2

After a while of searching and doing research I found out the issue I had was with the email client's security policies blocking me from embedding images into HTML format emails.

cid: img

The above tag DID work but not through the sending of SSMS because of the security policies.

The solution to this problem was hosting the images securely on a site with a SSL certificate; generating a direct link to said image and placing that link as the source inside the html image tag.

Astora
  • 55
  • 2
  • 5