2
Answers

Security exception when constructing system.net.mail.smtpClient. Need smtpPermission?

Willem

Willem

14y
7.9k
1
Hi all,

This is my first post, i'm very much a noobie, so sorry if this is an obvious one.

I am studying the 70-536 self paced training kit and using VS2010 for the excercises. In Chapter 15 : Mail the excersise is to create a mail sender application.

When I follow the steps they give it throws a security exception with the following message at the constructor of the smtpClient class:

Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

The finished code sample that they supply with the book also throws the same exception.

I have tried adding a permission.requestminimum attribute to the assembly and the code runs. I'm assuming it means that it has the nescesary permissions then, otherwise it would not have been able to run.

So far the code looks something like this:

//in assembly info file
[assembly: System.Net.Mail.SmtpPermission(System.Security.Permissions.SecurityAction.RequestMinimum)]

//above mail sender method
[SmtpPermission (System.Security.Permissions.SecurityAction.Demand)]

...omminting setup code...
// Configure the mail server
SmtpClient sc = new SmtpClient(serverTextBox.Text);

Thank you for any help.
Answers (2)