0

How can we encode the image into the body of the email when sending mail using database mail in sql 2008 I m using :

    exec msdb.dbo.sp_send_dbmail
    @profile_name = 'DBMail',
    @recipients = 'goldenash21@gmail.com',
    @subject = 'DB hello',
    --@file_attachments = 'C:\logo.jpg',    
    @body='<p>Image Test</p><img src="C:\logo.jpg" width="270" height="146"" /><p>See image there?</p>' , 
    @body_format = 'HTML';

Any help would be highly appreciable.. Thanks

Ashok Gupta
  • 2,247
  • 5
  • 28
  • 34
  • 1
    If your HTML says that the image source is `c:\logo.jpg` then the email reader needs to be able to see that file at `c:\logo.jpg`, *on their computer*. Try hosting the image online and using a URL that references the online file? – MatBailie Jan 12 '12 at 11:25
  • Thanks .. Passing online reference of image works ... :) – Ashok Gupta Jan 12 '12 at 12:21

1 Answers1

1

You've almost done it:

exec msdb.dbo.sp_send_dbmail
@profile_name = 'DBMail',
@recipients = 'goldenash21@gmail.com',
@subject = 'DB hello',
@file_attachments = 'C:\logo.jpg;C:\logo2.jpg;',    
@body='<p>Image Test</p><img src="logo.jpg" width="270" height="146"" /><p>See image there?</p><img src="logo2.jpg" width="270" height="146"" />' , 
@body_format = 'HTML';

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

Michał Powaga
  • 22,561
  • 8
  • 51
  • 62