SmtpMail and WbClient security exceptions

Discussion in 'Site Programming, Development and Design' started by alex, Sep 23, 2009.

  1. Hi,

    I'm trying to send e-mail with SmtpMail class and getting security exception:
    Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    The same situation while trying to access another web site (RSS feed) via WebClient. The exception is thrown:
    Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    Is it Winhost security limitations or some settings can be adjusted to allow this functionality?

    SourceCode for e-mail sending (executed on a separate thread):
    //prepare E-mail client
    SmtpClient client = new SmtpClient();
    client.UseDefaultCredentials = false;

    client.Host = "smtp.gmail.com";
    client.Port = 587;
    client.EnableSsl = true;
    client.Credentials = new NetworkCredential(settings.EmailAccount, settings.EmailPassword);
    var message = new MailMessage(settings.EmailAccount, to, subject, settings.MessageBody);

    client.Send(message);

    Thanks
     
  2. Ray

    Ray

    Did you check what trust mode your application is running? Try setting it to use Full trust mode.
     
  3. Last edited: Oct 14, 2015
  4. Thanks, Ray and Hank, this helped me.
     

Share This Page