Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

How to imbed an image into an email sent by dbmail Expand / Collapse
Author
Message
Posted Tuesday, June 22, 2010 1:30 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, June 23, 2014 6:24 AM
Points: 42, Visits: 98
Hello all and thank you in advance for your time and expertise.

I am sending out customer statements in email using dbmail on sql 2008. I'd like to put our corporate logo on top of the email, but I'm having difficulty doing it. I found an article on the web that showed me how to put html tags into documents (I'm not a programmer, in case you can't tell ) and I have this line in my sql statement:
<img src="\\waccounting\images\logo.gif" width="400" height="100" border="0"/>

When the email goes out, the image is blank on the email. Has anyone been able to put an image into their emails that get sent out by dbmail? If so, how?
Post #941321
Posted Tuesday, June 22, 2010 4:43 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, November 11, 2014 2:38 PM
Points: 24, Visits: 387
I don't have an answer as I've never done this, but you're referring to a local server as the image storage location.

Is this email only going to an intranet where all recipients would have access to this server & file?

Could it be an issue of needing to actually attach the image to the email?

Jim
Post #941411
Posted Tuesday, June 22, 2010 6:47 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, April 1, 2014 11:20 AM
Points: 263, Visits: 275
Keep in mind that most email clients do not automatically load images in emails for privacy reasons. I expect that isn't the issue, but I wanted to mention it.

The problem is probably your file URI, which is incorrect.

Try this:

<img src="file://waccounting/images/logo.gif" width="400" height="100" border="0"/>



SQL guy and Houston Magician
Post #941439
Posted Wednesday, June 23, 2010 6:52 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, June 23, 2014 6:24 AM
Points: 42, Visits: 98
This is going externally - it's going out to our customers. I want to put our logo at the top of the email. Right now, it's blank.
Post #941713
Posted Wednesday, June 23, 2010 6:54 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, June 23, 2014 6:24 AM
Points: 42, Visits: 98
Robert Cary (6/22/2010)
Keep in mind that most email clients do not automatically load images in emails for privacy reasons. I expect that isn't the issue, but I wanted to mention it.

The problem is probably your file URI, which is incorrect.

Try this:

<img src="file://waccounting/images/logo.gif" width="400" height="100" border="0"/>



Robert,
Thanks for the input, but it still didn't work. You are right - outlook did block the image. But when I allowed the image to come through, it still showed blank.
Post #941714
Posted Wednesday, June 23, 2010 8:40 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:09 AM
Points: 12,965, Visits: 32,541
the secret is to use cid:attachedimage.gif for the source file.

here's a setup and working example:
I'm attaching the results of a query, and i copied the SQl server logo to my C:\ drive of my sql server.

declare @body1 varchar(4000)
set @body1 = '<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="cid:sqlservercentral_logo.gif" width="235" height="70" border="0" alt=""></td></tr>
</table>
</body>'
EXEC msdb.dbo.sp_send_dbmail
@profile_name='MyDefault EmailProfile',
@recipients='lowell@somedomain.net',
@subject = 'SQl 2008 email test',
@body = @body1,
@body_format = 'HTML',
@query = 'SELECT top 3 * from sysobjects where xtype=''U''',
@query_result_header = 0,
@exclude_query_output = 1,
@append_query_error = 1,
@attach_query_result_as_file = 1,
@query_attachment_filename = 'results.txt',
@query_result_no_padding = 1,
@file_attachments = 'C:\sqlservercentral_logo.gif'




Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #941817
Posted Wednesday, June 23, 2010 9:45 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, June 23, 2014 6:24 AM
Points: 42, Visits: 98
Lowell (6/23/2010)
the secret is to use cid:attachedimage.gif for the source file.

here's a setup and working example:
I'm attaching the results of a query, and i copied the SQl server logo to my C:\ drive of my sql server.

declare @body1 varchar(4000)
set @body1 = '<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="cid:sqlservercentral_logo.gif" width="235" height="70" border="0" alt=""></td></tr>
</table>
</body>'
EXEC msdb.dbo.sp_send_dbmail
@profile_name='MyDefault EmailProfile',
@recipients='lowell@somedomain.net',
@subject = 'SQl 2008 email test',
@body = @body1,
@body_format = 'HTML',
@query = 'SELECT top 3 * from sysobjects where xtype=''U''',
@query_result_header = 0,
@exclude_query_output = 1,
@append_query_error = 1,
@attach_query_result_as_file = 1,
@query_attachment_filename = 'results.txt',
@query_result_no_padding = 1,
@file_attachments = 'C:\sqlservercentral_logo.gif'




That was it. My other problem was the @file_attachments parameter - I didn't have that. Thank you very much!
Post #941884
Posted Wednesday, June 23, 2010 9:50 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 8:50 AM
Points: 5,370, Visits: 9,018
Cool, I was hoping that there was a solution for this, it just sounded like a reasonable thing to do.

Good job Lowell!

(Now if only one could bookmark a forum post on this site...)


Wayne
Microsoft Certified Master: SQL Server 2008
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #941887
Posted Wednesday, June 23, 2010 10:04 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 12:56 AM
Points: 210, Visits: 679
Thanks to forum (again) , i have something new to offer to my client...

Cheers
Post #941899
Posted Wednesday, May 18, 2011 2:42 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 3:40 PM
Points: 118, Visits: 569
I will have an upcoming use of printing a logo in my emails out to clients. I stumbled onto this forum looking for the syntax to use sp_send_dbmail without setting up the Database Mail client (like what credentials do I use to pass to the SMTP server?). This is the cart before the horse, but you guys are great and I won't have any problem with how my email will appear. Another satisfied customer of SSC!!
Post #1111350
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse