Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am sending Email with images in asp .net but not able to send image as div background?

What I have tried:

HTML
<pre lang="text">
<img src="cid:image1" />
<div style="background-image:url(cid:image2)">
<p>This is Text!</p>
</div>
</pre>



C#
Email Code.

string image1Path= HttpContext.Current.Server.MapPath(@"~/Images/image1.png");
string image2Path= HttpContext.Current.Server.MapPath(@"~/Images/image2.png");

 LinkedResource lnk1= new LinkedResource(image1Path);
 LinkedResource lnk2= new LinkedResource(image2Path);

 lnk1.ContentId = "image1";
 lnk2.ContentId = "image2";

AlternateView av1 = AlternateView.CreateAlternateViewFromString("" + htmlTemplate, null, MediaTypeNames.Text.Html);
      

av1.LinkedResources.Add(image1);
av1.LinkedResources.Add(image2);
       
message.AlternateViews.Add(av1);
Posted
Updated 25-Oct-16 0:16am
v6

Put Cursor on div tag and press F4 and in properties style in that background set image
 
Share this answer
 
Comments
Karthik_Mahalingam 27-Oct-16 2:28am    
5
I think you missed background-image css property.
 
Share this answer
 
Hi,

Have you debugged the code, R u getting image from the path?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900