Not sure if anyone has used 1and1 MS Hosting and encountered problems with their trust levels?
I am simply trying to send mail using system.net.mail in asp.net (which works fine) but when its online with 1and1 I get this error:
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.
I asked 1and1 and they sent me a machine.config file with their settings but no explanation with what to do with it.
Sorry I can't put up with there useless tech support any more.
Anyone got any ideas what I should do with the machine.config or something?
And the answer is........
1and1 do not allow access to system.net.mail. But do however allow access the obsolete system.web.mail (oh joy)
basic instructions with available mail server here
Almost any shared hosting (you only have access to a FTP site) is going to be medium trust. Its a common limitation. You have to develop against a medium trust server in order to weed out those issues. Sometimes they're easy to deal with, sometimes not.
An alternative is to do virtual hosting. You get a virtual server that you can administer yourself. That way you can run your websites under full trust. I do that with my 1and1 website. While people bitch about them (what host doesn't have people bitching about it?) they have the cheapest virtual servers out there, last time I checked.
Is it possible that your host's smtp server requries some type of authentication to relay the mail? That is all I can think of. When you instantiate the SmtpClient, try setting the credentials, I'm not certain what credentials you would supply, perhaps something from your hosting provider?
You could also try modifying your web.config and changing the trust level in there. I've had similar issues in the past with a couple of other hosts, and this worked for me: