Cannot embed a jpg image in a database mail email

  • The information in this earlier post just isn't working for me at all.  It's good information and it got me started, but ultimately it isn't working.

    https://qa.sqlservercentral.com/Forums/941321/How-to-imbed-an-image-into-an-email-sent-by-dbmail?PageIndex=1

    I have a folder on my Server's C: drive that contains two files: Dashboard.pdf and Dashboard.jpg. These files are overwritten on a daily basis. All I want to do is use database mail to send the Dashboard.PDF file as an attachment and embed Dashboard.jpg in the body of the email. That's it.

    The email is being sent with the files attached perfectly.

    Here's the code . . .

    DECLARE @body1 varchar(4000)
    set @body1 = '<head>
    <title> Dashboard </title>
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    </head>
    <body>
    <table><tr><td valign="top" align="left"><img src="cid:Dashboard.jpg" border="0" alt=""></td></tr>
    </table>
    </body>'

    EXEC msdb.dbo.sp_send_dbmail
    @recipients=N'klgtest@gmail.com',
    @body= @body1,
    @body_format = 'HTML',
    @subject = 'Dashboard',
    @profile_name = 'EmailReports',
    @file_attachments ='c:\Dashboard.jpg;c:\Dashboard.pdf'

    Both attachments are sent and received but the jpg won't embed inside the email body. The size of the file doesn't seem to be the problem. And since the files are being sent, I don't think it's a database mail issue.  I've tried some pairs of small images and nothing comes out in the body of the email.  

    I hope you or someone here can help.

    Thanks!
    Karen 

  • Karen Grube - Tuesday, August 14, 2018 6:17 PM

    The information in this earlier post just isn't working for me at all.  It's good information and it got me started, but ultimately it isn't working.

    https://qa.sqlservercentral.com/Forums/941321/How-to-imbed-an-image-into-an-email-sent-by-dbmail?PageIndex=1

    I have a folder on my Server's C: drive that contains two files: Dashboard.pdf and Dashboard.jpg. These files are overwritten on a daily basis. All I want to do is use database mail to send the Dashboard.PDF file as an attachment and embed Dashboard.jpg in the body of the email. That's it.

    The email is being sent with the files attached perfectly.

    Here's the code . . .

    DECLARE @body1 varchar(4000)
    set @body1 = '<head>
    <title> Dashboard </title>
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    </head>
    <body>
    <table><tr><td valign="top" align="left"><img src="cid:Dashboard.jpg" border="0" alt=""></td></tr>
    </table>
    </body>'

    EXEC msdb.dbo.sp_send_dbmail
    @recipients=N'klgtest@gmail.com',
    @body= @body1,
    @body_format = 'HTML',
    @subject = 'Dashboard',
    @profile_name = 'EmailReports',
    @file_attachments ='c:\Dashboard.jpg;c:\Dashboard.pdf'

    Both attachments are sent and received but the jpg won't embed inside the email body. The size of the file doesn't seem to be the problem. And since the files are being sent, I don't think it's a database mail issue.  I've tried some pairs of small images and nothing comes out in the body of the email.  

    I hope you or someone here can help.

    Thanks!
    Karen 

    I know this is of little help, but I copied and pasted your code into SSMS and created files on my servers c drive Called Dashboard.jpg and dashboard.pdf and it worked fine. So there doesn't appear to be anything wrong with your code.

    Regards

  • Actually, that does help a lot.  It tells me we either have something set up differently or incorrectly in our connection to gmail's outgoing smtp server or there's some security issue somewhere blocking the image.  Thank you!

  • Okay, I tried sending a very small scheduled SSRS report as MHTML from our server and the report didn't display in the email client. THEN I looked at the RAW email and saw that it was being sent from our server using an old ip address set up for ipv4. I'm working with our server hosting provider to correct that to our newer ip address and we'll see if it resolves the problem. WOW! I'll let everyone know.

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

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