Hi All...
What I'm trying to do
I'm trying to send an email with a background image, using ASP.NET 3.5. I am formatting the email as follows:
... and the C# code I'm using looks something like this (some lines are missing, but you get the idea):
The Problem
When viewing the email (at least from yahoo, gmail, and hotmail) the background image (imgBg) does not show up. Everything else shows up correctly (including the header image), but I get a white background instead of the intended background image.
Now the background image is part of the email, and I see it as an attachment, but it is not shown as a background.
What I have tried
I have tried (to no avail) all sorts of things in order to get this thing to work.
1. Instead of using linked resources, I have tried adding a direct link to the image, that is: background-image:url( Same problem. The header image shows correctly (using src=" and the background does not show up.
2. I have tried background:cid:imgBg and background: (with and without quotes) instead of background-image:url(...). Same differerence.
3. Instead of using AlternateView, I have just set mailMessage.Body to the html code (with and without the linked resources) - no good.
4. Instead of <table background/-image...> I have used the whole <html><body> tags... to no avail.
5. Instead of <table> tags I have used <div> tags for the outer container that has the background image... Same issue.
An Interesting Detail
A friend of mine uses an email reader similar to Outlook on a Mac, and the background image displays correctly there, so the code works... somewhere, at least.
The Question
How on earth do I get the background image to display on gmail, yahoo, hotmail, etc?
Thanks.
_________________________________
I think, therefore I am. [Rene Descartes]
What I'm trying to do
I'm trying to send an email with a background image, using ASP.NET 3.5. I am formatting the email as follows:
Code:
[COLOR=blue]string[/color] htmlBody = @"
<table [b][COLOR=red]style='background-image:url(cid:imgBg)[/color][/b]; padding:0px;'>
<tr>
<td colspan='2'>
<img alt='' src=cid:imgHeader />
</td>
</tr>
.
. [COLOR=green]// some more stuff here[/color]
.
</table>";
Code:
[COLOR=blue]string[/color] nl = Environment.NewLine;
mailMessage.Body = [COLOR=brown]"Message from contact page:" [/color]+ nl + nl +
[COLOR=brown]"Name: "[/color] + txtName.Text + nl +
[COLOR=brown]"Email: "[/color] + fromEmail + nl +
[COLOR=brown]"Subject: "[/color] + subject + nl + nl +
[COLOR=brown]"Message: "[/color] + nl + txtMsg.Text;
[b][COLOR=purple]LinkedResource[/color] imgBg = new [COLOR=purple]LinkedResource[/color](Server.MapPath("images/bg.jpg"), MediaTypeNames.Image.Jpeg);
imgBg.ContentId = "imgBg";[/b]
[COLOR=purple]LinkedResource[/color] imgHeader = new [COLOR=purple]LinkedResource[/color](Server.MapPath("images/header.jpg"), MediaTypeNames.Image.Jpeg);
imgHeader.ContentId = "imgHeader";
[COLOR=purple]AlternateView[/color] htmlView = [COLOR=purple]AlternateView[/color].CreateAlternateViewFromString(htmlBody, Encoding.ASCII, MediaTypeNames.Text.Html);
htmlView.LinkedResources.Add(imgBg);
htmlView.LinkedResources.Add(imgHeader);
mailMessage.AlternateViews.Add(htmlView);
mailMessage.IsBodyHtml = true;
When viewing the email (at least from yahoo, gmail, and hotmail) the background image (imgBg) does not show up. Everything else shows up correctly (including the header image), but I get a white background instead of the intended background image.
Now the background image is part of the email, and I see it as an attachment, but it is not shown as a background.
What I have tried
I have tried (to no avail) all sorts of things in order to get this thing to work.
1. Instead of using linked resources, I have tried adding a direct link to the image, that is: background-image:url( Same problem. The header image shows correctly (using src=" and the background does not show up.
2. I have tried background:cid:imgBg and background: (with and without quotes) instead of background-image:url(...). Same differerence.
3. Instead of using AlternateView, I have just set mailMessage.Body to the html code (with and without the linked resources) - no good.
4. Instead of <table background/-image...> I have used the whole <html><body> tags... to no avail.
5. Instead of <table> tags I have used <div> tags for the outer container that has the background image... Same issue.
An Interesting Detail
A friend of mine uses an email reader similar to Outlook on a Mac, and the background image displays correctly there, so the code works... somewhere, at least.
The Question
How on earth do I get the background image to display on gmail, yahoo, hotmail, etc?
Thanks.
_________________________________
I think, therefore I am. [Rene Descartes]