I was checking out the new System.Net.Mail class and noticed the LinkedResource...does anyone know of an example using a LinkedResource How does one reference the LinkedResource from the email body
You have to use AlternateView to use LinkedResources. Instead of Message.Body, you can create a AlternateView (to which you add LinkedResources) and then add it to Message.AlternateView
Sample code is
//SET FROM, TO
MailMessage Message =
new MailMessage("<from>", "<TO>"); //SET SUBJECT
Message.Subject =
"System.Net.Mail is easy"; //LINKED RESOURCES
LinkedResource expresssql =
new LinkedResource("expresssql.jpg", "image/jpeg");
expresssql.ContentLink =
new Uri("http://lab.msdn.microsoft.com/vs2005/art/expresssql.jpg");
LinkedResource expressvb =
new LinkedResource("expressvb.jpg", "image/jpeg");
expressvb.ContentLink =
new Uri("http://lab.msdn.microsoft.com/vs2005/art/expressvb.jpg");
LinkedResource expressvcplusplus =
new LinkedResource("expressvcplusplus.jpg", "image/jpeg");
expressvcplusplus.ContentLink =
new Uri("http://lab.msdn.microsoft.com/vs2005/art/expressvcplusplus.jpg");
LinkedResource expressvcsharp =
new LinkedResource("expressvcsharp.jpg", "image/jpeg");
expressvcsharp.ContentLink =
new Uri("http://lab.msdn.microsoft.com/vs2005/art/expressvcsharp.jpg");
LinkedResource expressvjsharp =
new LinkedResource("expressvjsharp.jpg", "image/jpeg");
expressvjsharp.ContentLink =
new Uri("http://lab.msdn.microsoft.com/vs2005/art/expressvjsharp.jpg");
LinkedResource expressvwd =
new LinkedResource("expressvwd.jpg", "image/jpeg");
expressvwd.ContentLink =
new Uri("http://lab.msdn.microsoft.com/vs2005/art/expressvwd.jpg"); //ADD Linked Resources
I've tried this. I don't get any errors, but when I receive the e-mail it is not like in the html file. The pictures are attached in the mail, but i cannot see the e-mail like the html file. Why is that
system.net.mail class question
dakhili
regthesk8r
Gagnar,
You have to use AlternateView to use LinkedResources. Instead of Message.Body, you can create a AlternateView (to which you add LinkedResources) and then add it to Message.AlternateView
Sample code is
//SET FROM, TO
MailMessage Message =
new MailMessage("<from>", "<TO>"); //SET SUBJECTMessage.Subject =
"System.Net.Mail is easy"; //LINKED RESOURCESLinkedResource expresssql =
new LinkedResource("expresssql.jpg", "image/jpeg");expresssql.ContentLink =
new Uri("http://lab.msdn.microsoft.com/vs2005/art/expresssql.jpg");LinkedResource expressvb =
new LinkedResource("expressvb.jpg", "image/jpeg");expressvb.ContentLink =
new Uri("http://lab.msdn.microsoft.com/vs2005/art/expressvb.jpg");LinkedResource expressvcplusplus =
new LinkedResource("expressvcplusplus.jpg", "image/jpeg");expressvcplusplus.ContentLink =
new Uri("http://lab.msdn.microsoft.com/vs2005/art/expressvcplusplus.jpg");LinkedResource expressvcsharp =
new LinkedResource("expressvcsharp.jpg", "image/jpeg");expressvcsharp.ContentLink =
new Uri("http://lab.msdn.microsoft.com/vs2005/art/expressvcsharp.jpg");LinkedResource expressvjsharp =
new LinkedResource("expressvjsharp.jpg", "image/jpeg");expressvjsharp.ContentLink =
new Uri("http://lab.msdn.microsoft.com/vs2005/art/expressvjsharp.jpg");LinkedResource expressvwd =
new LinkedResource("expressvwd.jpg", "image/jpeg");expressvwd.ContentLink =
new Uri("http://lab.msdn.microsoft.com/vs2005/art/expressvwd.jpg"); //ADD Linked ResourcesAlternateView htmlBody =
new AlternateView("VS2005.htm", "text/html");htmlBody.LinkedResources.Add(expresssql);
htmlBody.LinkedResources.Add(expressvb);
htmlBody.LinkedResources.Add(expressvcplusplus);
htmlBody.LinkedResources.Add(expressvcsharp);
htmlBody.LinkedResources.Add(expressvjsharp);
htmlBody.LinkedResources.Add(expressvwd);
//Add it to the MessageMessage.AlternateViews.Add(htmlBody);
david123098
I also study this question
enrialva
I've tried this. I don't get any errors, but when I receive the e-mail it is not like in the html file. The pictures are attached in the mail, but i cannot see the e-mail like the html file. Why is that
Thanks
David Blaettler