views:

2499

answers:

7

I have an ASP.NET application hosted on Godaddy that I want to send email from. When it runs, I get: Mailbox name not allowed. The server response was: sorry, relaying denied from your location. The important parts of the code and Web.config are below:

msg = new MailMessage("[email protected]", email);
        msg.Subject = "GreekTools Registration";
        msg.Body =
            "You have been invited by your organization to register for the GreekTools recruitment application.<br/><br/>" +
            url + "<br/><br/>" +
            "Sincerely,<br/>" +
            "The GreekTools Team";

        msg.IsBodyHtml = true;

        client = new SmtpClient();
        client.Host = "relay-hosting.secureserver.net";

        client.Send(msg);

<system.net>
<mailSettings>
  <smtp from="[email protected]">
    <network host="relay-hosting.secureserver.net" port="25" userName="********" password="*********" />
  </smtp>
</mailSettings>

A: 

This is likely a reply from the SMTP server because the machine attempting to send email has not been whitelisted (or is blacklisted for SPAM). Is relay-hosting.secureserver.net a GoDaddy server, or is it on a different network? You might want to find a GoDaddy server that enables email to be relayed. I would imagine a lot of shared hosting providers have restrictions today.

I would find out what type of SMTP server you are using and what anti-spam measures are in place. The administrator may be able to add the GoDaddy server to the whitelist of allowed hosts. You need to be very careful and make sure that you application cannot be used as a proxy for a spammer. Make sure to validate all input to ensure it it safe.

BrianLy
relay-hosting.secureserver.net is GoDaddy's smtp relay server.
Jared
A: 

Check your hostname. Are you sure your account isn't configured to use mail.greektools.net ?That's the default format for GoDaddy webhosting..

Scott Ferguson
I did try to change it to mail.greektools.net and I got a generic "failure to send" exception (or something like that).
Jared
A: 

set

defaultCredentials="false"

in your network element

     <network host="relay-hosting.secureserver.net" port="25" userName="********" password="*********" defaultCredentials="false" />
krishna
A: 

Hi, Just for a test. Remove the username and password values from the web.config.

Then, in your code set

//call this line, before you call .Send
client.Credentials = CredentialCache.DefaultNetworkCredentials; 
client.Send(msg)

Cheers! Dave

dave wanta
A: 

I just asked GoDaddy, how to set up a SMTP form mailer, and they told me that I'd need to use a Relay Server, with no username, no password, and no port. The server name to use was, the same name that you used.

Thanks, Brad.

Brad
+2  A: 

Here's my email class:

public class Email
{
    public enum MailAddressType
    {
        From = 1,
        Bcc
    }

    private static MailAddress _from = null;

    public static void SendEmail(string to, string subject, string body)
    {
        SendEmail(to, subject, body, From, string.Empty);
    }

    public static void SendEmail(string to, string subject, string body, string from)
    {
        SendEmail(to, subject, body, from, MailAddressType.From);
    }

    public static void SendEmail(string to, string subject, string body, string addresses, MailAddressType addressType)
    {
        MailAddress from = From;
        string bcc = string.Empty;

        if (MailAddressType.From == addressType)
        {
            from = new MailAddress(addresses);
        }
        else
        {
            bcc = addresses;
        }

        SendEmail(to, subject, body, from, bcc);
    }

    private static void SendEmail(string to, string subject, string body, MailAddress from, string bcc)
    {
        MailMessage message = new MailMessage();
        message.From = From;
        message.To.Add(to);
        if (!string.IsNullOrEmpty(bcc))
        {
            message.Bcc.Add(bcc);
        }
        message.ReplyTo = from;
        message.Subject = subject;
        message.Body = HttpContext.Current.Server.HtmlEncode(body);
        SmtpClient smtp = new SmtpClient();
        smtp.Send(message);
    }

    public static MailAddress From
    {
        get
        {
            if (null == _from)
            {
                SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
                string address = section.From;
                string displayName = ConfigurationManager.AppSettings["fromEmailDisplayName"];
                _from = new MailAddress(address, displayName);
            }
            return _from;
        }
    }
}

And here are the related web.config settings:

<appSettings>
    <add key="fromEmailDisplayName" value="Firstname Lastname"/>
</appSettings>

<system.net>
    <mailSettings>
        <smtp deliveryMethod="Network" from="[email protected]">
            <network host="relay-hosting.secureserver.net" />
        </smtp>
    </mailSettings>
</system.net>

For me, the key was "message.From = From" and "message.ReplyTo = from". GoDaddy seems to want the message to come from an address in your domain. So for contact pages, use your default email address as the From and set the sender as the ReplyTo. Email goes through fine after that.

Rich Bennema
A: 

What email or relay server should I use in my ASP.NET 3.5 code?

You do not need to provide a user name and password for this relay server.

kervin