6

I can't send email via ASP.NET and sent an email to my web hosts for some help and was told to modify my security settings and was sent a link:

http://forums.asp.net/t/1111145.aspx/1

I've read what it said there and tried setting <trust level="Full" originUrl="" /> in web.config, but then I get the error:

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.

I've not set any other web.config file.

So I asked the web hosts again, and asked if it was a server setting which I cannot change, but the response I got was just:

You'll need to specify a more specific path.

Which is lovely, but I've no idea what that means!

Having done a bit more digging I am wondering if I have to set up a separate trust file, is this correct?

Could someone point me in the direction of the correct way to set up my Trust level (I realise "full" is probably incorrect as well?) as I really don't understand what I am supposed to do!

Jamie Hartnoll
  • 7,231
  • 13
  • 58
  • 97

2 Answers2

8

Trust levels are documented here: http://msdn.microsoft.com/en-us/library/ie/wyts434y.aspx. In shared hosting, providers lock that settings, so you cannot change in your web.config. If you clearly requested from your provider to allow full trust to your application, and if they responded with "huh?", then you were talking to an uneducated person - either request escalation or change hosts. "Please configure my application with full trust" should be clear enough. Note that they may not be willing to do that, once they understand your request.

Also, I cannot be sure that full trust is required to send mail out. Sending mail out involves ability to communicate to an SMTP server, and usually web hosts allow accessing only theirs and they block everything else (for spam prevention). You will not be able to talk them into making an exception for you, but if you ask "please tell me which smtp and port to use to send email out from my asp.net application", they should give it to you (otherwise, escalate or change hosts). You actually should have asked them to help you send mail out first, before you made conclusion that trust-level is what's obstructing it (now, I'm pretty sure it doesn't).

Also, read this, please: https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem

Community
  • 1
  • 1
  • Thanks. So what you're saying is that their answer was even more unhelpful than I realised! Referring to your point that I should have asked them how to send mail through their servers first... Actually, I did! I emailed them some sample code and was told that should be fine to use. Then I ran into the problem which inspired me to post here. I'll email them again requesting a more complete response. – Jamie Hartnoll Jan 30 '12 at 20:36
  • I'm pretty sure I had an app in shared hosting with partial trust send out mail. Hosts will unlikely give you full trust, because that poses a risk to their server and other apps running on it; they'll use that opportunity to advertize their dedicated servers, typically. Use .NET's classes to send email out (or at least to test it working) before you start using some 3rd party mailer libraries (you can find sample code out there; it takes only a few lines + few web.config changes). Then, if sending mail fails, paste exception info here; and we'll figure something out. –  Jan 30 '12 at 22:23
  • 1
    Yes, most of shared hosting doesnt support Full Trust, so you need to check it with your current provider. But, if you really need full trust hosting, I can give one name, HostForLife.eu. You can find their site on Microsoft site. :) –  Jan 31 '12 at 02:39
  • Argh! I have it sorted now, I need to use Port 25. http://www.west-wind.com/weblog/posts/2008/Jan/18/SmtpClient-in-Medium-Trust why on Earth they couldn't have told me that int he first place when I initially sent the code to them to check!! :@ – Jamie Hartnoll Jan 31 '12 at 09:52
  • Yes it does! Just wish they'd mentioned that before I started faffing around!! Default trust is medium apparently and using port 25 it's all working! – Jamie Hartnoll Feb 01 '12 at 21:15
-3

Try this:

 public static void ConfirmMail(string emailTo)

{
    try
    {

        MailMessage message = new MailMessage();
        message.Subject = "Account Registration From 91calls";
        message.From = new MailAddress(Convert.ToString("admin@91calls.com"),"Admin");
        message.To.Add(emailTo);
        message.BodyEncoding = System.Text.Encoding.UTF8;
        StringBuilder sb = new StringBuilder();
        sb.Append("<html>");
        sb.Append("<Body>");
        sb.Append("<table cellpadding='0' cellspacing='0' width='100%' border='0'>");
        sb.Append("<tr><td align='center'><table cellpadding='0' cellspacing='0' width='100%' border='0'>");
       // sb.Append("<tr><td align='left'><asp:Image ID='imgLogo' runat='server' ImageUrl='http://supervau.w01.winhost.com/images/logo.png' />");
        sb.Append("</td></tr><tr><td>Hi, <br></td></tr><tr><td align='left'>You are successfylly resgistered with 91 calls.<br>");
        sb.Append("<br>Thank you for using, : http://www.91calls.com<br /><br>For questions or concerns regarding your account, please visit : http://www.91calls.com");
        sb.Append("</td></tr></table></td></tr></table>");
        sb.Append("</Body>");
        sb.Append("</html>");
        message.Body = sb.ToString();
        message.IsBodyHtml = true;
        SmtpClient client = new SmtpClient();
        client.Send(message);


    }
    catch
    {
    }

}
Baby Groot
  • 4,637
  • 39
  • 52
  • 71