Cannot send email in ASP.NET through Godaddy servers
Asked Answered
B

12

6

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>

Broadcast answered 1/9, 2009 at 2:2 Comment(0)
P
21

1- If your site is hosted on godaddy you may use "relay-hosting.secureserver.net" without credentials.

2- If your site is hosted outside of godaddy you may use "smtpout.secureserver.net" with you email account credentials.

PS: Please change port 3535 if you have problems with 25

Hosted On GoDaddy

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

External

  <system.net>
    <mailSettings>
      <smtp from="[email protected]">
        <network host="smtpout.secureserver.net" 
           userName="[email protected]" password="your_password_here" 
           port="25" />
      </smtp>
    </mailSettings>
  </system.net>
Plerre answered 4/1, 2011 at 13:51 Comment(3)
I was having issues when using relay-hosting.secureserver.net as the smtpClient.Host. Sometimes it took a long time to send, and others it would send at all throwing an exception: "Mailbox name not allowed. The server response was: sorry, relaying denied from your location". Changing my host to smptout.secureserver.net resolved this issue and allows the mail to be sent in seconds. Thank you very much :D +1Bandoline
godaddy made some changes with their email infrastructure. You can create your email account in different data centers. so you can chose America, europe or asia servers. For that reason you need to use a smtp server for your region. like "smtpout.europe.secureserver.net"Plerre
My problem was port 25. Thanks a lot for suggesting port 3535. Worked like a charm!Okeechobee
A
2

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.

Anglo answered 21/3, 2010 at 21:41 Comment(0)
R
0

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.

Rimple answered 1/9, 2009 at 2:7 Comment(1)
relay-hosting.secureserver.net is GoDaddy's smtp relay server.Broadcast
C
0

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

Coquetry answered 1/9, 2009 at 4:7 Comment(1)
I did try to change it to mail.greektools.net and I got a generic "failure to send" exception (or something like that).Broadcast
S
0

set

defaultCredentials="false"

in your network element

     <network host="relay-hosting.secureserver.net" port="25" userName="********" password="*********" defaultCredentials="false" />
Statist answered 1/9, 2009 at 13:26 Comment(0)
B
0

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)
Boulevard answered 1/9, 2009 at 13:32 Comment(0)
A
0

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.

Amorphous answered 3/11, 2009 at 21:31 Comment(0)
M
0

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.

Maier answered 21/3, 2010 at 21:50 Comment(0)
M
0
var message = new MailMessage();
message.To.Add(new MailAddress("email-address")); 
message.From = new MailAddress("email-address");  
message.Subject = "subject";
message.Body = string.Format("message-body");
message.IsBodyHtml = true;
using (var smtp = new SmtpClient())
{
    smtp.Host = "relay-hosting.secureserver.net";
    smtp.EnableSsl = false;
    smtp.Credentials = CredentialCache.DefaultNetworkCredentials;
    await smtp.SendMailAsync(message);
}
Mohamed answered 5/3, 2016 at 3:48 Comment(0)
B
0

For those who want to know what should be C# code in addition to the accepted answer, below code worked for me. Please note that "from" address is already mentioned in web.config in the accepted answer, so no need to mention it in C# code.

    public static void SendMail(string emailid, string subject, string body)
    {
        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();

        System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();

        msg.To.Add(new MailAddress(emailid));

        msg.Subject = subject;
        msg.IsBodyHtml = true;
        msg.Body = body;

        client.Send(msg);
    }
Buyse answered 26/8, 2017 at 15:59 Comment(0)
B
0

Try below code:

smtp.Host = "relay-hosting.secureserver.net";
smtp.Port = 25;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "*******");

It worked for me.

Beggs answered 13/9, 2018 at 16:10 Comment(1)
Maybe give an explanation on how this code answers the question?Atlantes
E
0

The code working for me for Go Daddy email send from c# code

var smtp = new SmtpClient
{
  Host = "smtpout.secureserver.net",
  Port = 25,
  UseDefaultCredentials = false,
  Credentials = new NetworkCredential("domain.xyz.com", "password...")
};
using (var message = new MailMessage("domain.xyz.com", "domain.xyz.com")
 {
    IsBodyHtml = false,
    Subject = modal.Subject,
    Body = modal.Body
 })
  {
   smtp.Send(message);
  }
Electric answered 17/8, 2020 at 21:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.