Linked Resource Issues

Discussion in 'Email' started by ckennon, Jun 28, 2011.

  1. Hello,

    I am trying to send a html email with an embedded image in it, using a linked resource. When I test this, I receive the following exception:

    "Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) at System.Security.CodeAccessPermission.Demand() at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName, String mediaType) at BusinessObjects...."

    My code is as follows:

    //Create an email for the user with their de/selection.
    _message.To.Add(new MailAddress(ToEmailAddress, ToName));
    _message.From = new MailAddress(FromEmailAddress, FromName);
    _message.Subject = Subject;
    _message.IsBodyHtml = true;

    //Create alternative view.
    string htmlBody = "<html><body><img src=\"cid:Heading\"><br /><br />" + _text + "</body></html>";
    AlternateView avHtml = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);

    //Create a link resource for the heading image.
    LinkedResource heading = new LinkedResource(@"~/images/heading.jpg", MediaTypeNames.Image.Jpeg);
    heading.ContentId = "Heading";
    avHtml.LinkedResources.Add(heading);

    //Create an alternate view for unsupported clients.
    string textbody = text.Replace("<br />", "\r\n");
    AlternateView avText = AlternateView.CreateAlternateViewFromString(textbody, null, MediaTypeNames.Text.Plain);

    //Add the alternative views.
    _message.AlternateViews.Add(avHtml);
    _message.AlternateViews.Add(avText);

    Thanks very much for your help.
     
  2. FredC

    FredC Winhost Staff

    try elavate the trust level to full
     

Share This Page