tags:

views:

32

answers:

2

I am getting the following error on my page:

Security Exception 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.

The problem is with the following code

SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587);

What's weird is that when testing it at my localhost, everything works fine, but when I put it on my 1and1 web host it generates the error above. I contacted their support and here's their answer.

We do check the error logs and the operation require a FullTrust environment which currently fall under restriction on .NET Framewor

k

What should I do?

A: 

First off, if you want to reproduce this locally, you need to add a trust level of medium to your web.config.

The problem is that your application needs to make an outgoing request to an external mail server to send the mail. Outgoing requests are not allowed in medium trust environments. If you change the parameters to 'localhost', 25 it will probably work, but I am assuming youre using that mail server for a reason. (Maybe it was just for local development?)

Shawn Simon
this is actually used for a contact us form... I want to send an email to my email with the message that users type in the form
EquinoX
right so you want to change that line of code to new smptclient("localhost", 25)
Shawn Simon
but I don't have an email account in my web host yet
EquinoX
you are sending outgoing mail. the local mail server will handle sending it to your gmail account
Shawn Simon