views:

563

answers:

5

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?

Many Thanks!

+1  A: 

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?

RandomNoob
A: 

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.

Will
yeh but isn't system.net.mail only a medium trust proceedure? isn't this a standard way of sending mail? surely they wouldn't block this.
David
Medium trust means we don't trust you to get hijacked by a virus/vulnerability and start acting as a spam gateway.
Will
A: 

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:

<system.web>
    <trust Level="Full" />
</system.web>
Mun
one and one seems to not allow overides on this:Parser Error Message: This configuration section cannot be used at this path. This happens when the site administrator has locked access to this section using <location allowOverride="false"> from an inherited configuration file.
David
Yep, I think it was a long shot anyway :-)
Mun
+2  A: 

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

David
A: 

I have this problem too on http://www.hulkmedia.net on my contact form.

Calling 1and1.com to try and get this resolved. Do you have a copy of the machine.config file?

Daniel Newman
just use system.web.mail works straight away
David