system.net.mail class question

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

thanks in advance


Answer this question

system.net.mail class question

  • dakhili

    thanks.
  • 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 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

    AlternateView 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 Message

    Message.AlternateViews.Add(htmlBody);



     



  • david123098

    GOOD
    I also study this question

  • enrialva

    Hello,

    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

    Did you try setting IsBodyHtml to true You can find this property on MailMessage class.


  • system.net.mail class question