Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
My Code is:
Mail.To.Add("[email protected]");
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("[email protected]", "123");
client.EnableSsl = true;
client.Credentials = credentials;
string body = MailBody;
var mail = Mail;
MailAddress From = new MailAddress("[email protected]", "Test Mail");
mail.From = From;
mail.Subject = MailSubject;
mail.IsBodyHtml = true;
mail.Body = body;
client.Send(mail);