Error: Embeding pics in email

J

julito

Hi

I got the next problem, in the following code I want to send 3 pics (pic1,
pic2, pic3) in a html table. But when I send the message the user who
receives this message look a table with three repeated images. Exactly the
first pic in add to AlternateViews collection.

Somebody can help me?

My CODE:

string fromAddress = "(e-mail address removed)";
string toAddress = "(e-mail address removed)";

MailMessage mailMessage = new MailMessage(fromAddress, toAddress);
mailMessage.Subject = "Text";

string html = @"<html>
<body>
<table border=1>
<tr><td colspan=3>header</td></tr>
<tr><td colspan=3><br></td></tr>
<tr><td><img src=cid: pic1/><br></td>
<td><img src=cid: pic2/><br></td>
<td><img src=cid: pic3/><br></td>
</tr>
<tr><td colspan=3>footer</td></tr>
</table>
</body>
</html>";

AlternateView av1 =
AlternateView.CreateAlternateViewFromString(html, null,
System.Net.Mime.MediaTypeNames.Text.Html);
string strImageUrl1 = @"c:\pic-1.jpg";
LinkedResource pic1 = new LinkedResource(strImageUrl1,
System.Net.Mime.MediaTypeNames.Image.Jpeg);
pic1.ContentId = "pic1";
pic1.TransferEncoding = TransferEncoding.Base64;

AlternateView av2 =
AlternateView.CreateAlternateViewFromString(html, null,
System.Net.Mime.MediaTypeNames.Text.Html);
string strImageUrl2 = @"c:\pic-2.jpg";
LinkedResource pic2 = new LinkedResource(strImageUrl2,
System.Net.Mime.MediaTypeNames.Image.Jpeg);
pic2.ContentId = "pic2";
pic2.TransferEncoding = TransferEncoding.Base64;

AlternateView av3 =
AlternateView.CreateAlternateViewFromString(html, null,
System.Net.Mime.MediaTypeNames.Text.Html);
string strImageUrl3 = @"c:\pic-3.jpg";
LinkedResource pic3 = new LinkedResource(strImageUrl3,
System.Net.Mime.MediaTypeNames.Image.Jpeg);
pic3.ContentId = "pic3";
pic3.TransferEncoding = TransferEncoding.Base64;

av1.LinkedResources.Add(pic1);
av2.LinkedResources.Add(pic2);
av3.LinkedResources.Add(pic3);

mailMessage.AlternateViews.Add(av1);
mailMessage.AlternateViews.Add(av2);
mailMessage.AlternateViews.Add(av3);

mailMessage.IsBodyHtml = true;
SmtpClient mailSender = new SmtpClient("smtpclient.server.com");
//use this if you are in the development server
mailSender.Send(mailMessage);



Thanks for All
 
P

Patrice

Looks correct at first sight but I noticed that it seems you have a space
after cid: I would remove this. Also it would be likely better to enclose
attribute within quotes. Try :
src="cid:pic1" rather than
src=cid: pic1

Also make sure pic-1, pic-2, and pic-3 are not the same image ;-)
 
J

julito

When I remove this space the mail not show the pics. This show a table with 3
img labels but without any pic. But if there are 3 attached images.
 
P

Patrice

When I remove this space the mail not show the pics. This show a table
with 3
img labels but without any pic. But if there are 3 attached images.


So I tried your code and had the same problem

Using

<img src='cid:pic1'>

rather than

<img src=cid: pic1/>

fixed the problem...

It was the missing quotes (you can keep the self closing tag if this is
really XML). Without quotes the parser has no way to know where the
attribute value should stop so it will take the value up to the next non
usual character such as a blank or the : character so your code was seen as
<im src="cid" : pic1> or something similar...
 
J

julito

Oh Thanks!!!
This fix the problem!!!!

Patrice said:
So I tried your code and had the same problem

Using

<img src='cid:pic1'>

rather than

<img src=cid: pic1/>

fixed the problem...

It was the missing quotes (you can keep the self closing tag if this is
really XML). Without quotes the parser has no way to know where the
attribute value should stop so it will take the value up to the next non
usual character such as a blank or the : character so your code was seen as
<im src="cid" : pic1> or something similar...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top