Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Code is:
C#
protected void BtnSend_Click(object sender, EventArgs e)
    {
        try
        {
            MailMessage MM = new MailMessage(TxtFAddress.Text, TxtToAddress.Text, TxtSubject.Text, TxtMatter.Text);
            MM.IsBodyHtml = false;
            NetworkCredential Nc = new NetworkCredential(TxtFAddress.Text, "kattalavan0303");
            SmtpClient Sc = new SmtpClient("smtp.gmail.com", 587);
            Sc.UseDefaultCredentials = false;
            Sc.Credentials = Nc;
            Sc.EnableSsl = true;
            Sc.Send(MM);
            lblDisplay.Text = "Mail Delivered sucessfully";
        }
        catch (Exception ex)
        {
            lblDisplay.Text = ex.Message;
        }
    }
Posted
Updated 6-May-11 23:45pm
v3

Have you configured your app security to have sufficient trust?

If this is part of an ASP.NET web app, are you running on your own development / test machine or a public web server? If the latter you may need to ask your hosting company to give your app full (or at least greater) trust as you probably can't override their default trust settings yourself (for obvious reasons!).
 
Share this answer
 
Have you Googled for the error message? Here is the search result[^]

5690 results, isn't that amazing?

So in future do search before you ask. :thumbsup:
 
Share this answer
 
v2
Comments
NuttingCDEF 7-May-11 6:54am    
Or even . . .

http://lmgtfy.com/?q=Request+for+the+permission+of+type+%27System.Net.Mail.SmtpPermission%2C+System%2C+Version%3D2.0.0.0%2C+Culture%3Dneutral%2C+PublicKeyToken%3Db77a5c561934e089%27+failed
Ankur\m/ 7-May-11 7:01am    
Yeah, these questions more deserve LMGTFY links. :)
Member 8722604 16-Jun-12 17:06pm    
This is the first result on Google, idiot.
Ankur\m/ 17-Jun-12 3:44am    
What do you mean by that? I have anyways reported your comment and vote.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900