Click here to Skip to main content
15,885,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to send email with 2 embedded in which one image comes on top of another like there in one birthday wish image on which I want to set employee image. I am using following code.

C#
string Message = "<html><head></head><body>Dear Check,<br/><div style=\"removed: relative; removed 0; removed 0;\"><img style=\"position: relative; top: 0; left: 0;\" src=\"cid:birthdayCard\"></img><img style=\"position: absolute; left: 199px; top: 293px;\" src=\"cid:employeePhoto\"></img></div><br></body></html>";


<pre lang="c#">MailMessage message = new MailMessage(AdminEmail, RecipientEmail);
                                message.IsBodyHtml = true;
                                message.Subject = emailSubject;
                                message.From = new MailAddress(emailFrom);

                                AlternateView view = AlternateView.CreateAlternateViewFromString(Message, null, "text/html");
                                LinkedResource resource = new LinkedResource(attachmentPath);
                                resource.ContentId = "birthdayCard";
                                view.LinkedResources.Add(resource);

                                LinkedResource resource2 = new LinkedResource("C:/Users/crakhuc/Desktop/Small.jpg");
                                resource2.ContentId = "employeePhoto";
                                view.LinkedResources.Add(resource2);
                                message.AlternateViews.Add(view);
                               
                                message.IsBodyHtml = true;
                                SmtpClient client = new SmtpClient(smtpServer, Convert.ToInt32(portNumber));
                                client.Credentials = CredentialCache.DefaultNetworkCredentials;


C#
client.Send(message);


Problem with this is that its sending both image separately.
Posted

1 solution

Try like this you may get the result
string str = "<html><head></head><body>Dear Check,<br /><div style=\"removed: relative; removed 0; removed 0;\"> <img style=\"position: relative; top: 0; left: 0;\" src=\"http://www.google.com/imgres?imgurl=&imgrefurl=http%3A%2F%2Fwww.designsnext.com%2Fnature-wallpapers%2F&h=0&w=0&tbnid=-LkDg6OfUsMLZM&zoom=1&tbnh=197&tbnw=255&docid=9A7LVoILs90PjM&tbm=isch&ei=ICE2VIfUH4e3uATz74KgDw&ved=0CAcQsCUoAQ\"></img><img style=\"position: absolute; left: 199px; top: 293px;\" src=\"http://www.google.com/imgres?imgurl=&imgrefurl=http%3A%2F%2Fwww.designsnext.com%2Fnature-wallpapers%2F&h=0&w=0&tbnid=-LkDg6OfUsMLZM&zoom=1&tbnh=197&tbnw=255&docid=9A7LVoILs90PjM&tbm=isch&ei=ICE2VIfUH4e3uATz74KgDw&ved=0CAcQsCUoAQ\"></img></div><br></body></html>";



Please give the full path of an image.
 
Share this answer
 
v2
Comments
Samatha Reddy G 9-Oct-14 1:49am    
if you will not get please tell me i will give another solution
Member 9517802 9-Oct-14 2:26am    
Samatha I tried that but it doesnt work I gave path like file:///C:/Users/crakhuc/Desktop/Small.jpg this.
Samatha Reddy G 9-Oct-14 2:30am    
you cant access local system images on server, that image must be there in server.
Member 9517802 9-Oct-14 2:31am    
So where I have to save that images and how I have to give path
Samatha Reddy G 9-Oct-14 2:49am    
Please search that in google. how to host a image in server? you will get may solutions

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