Cannot send email in ASP.NET through Godaddy serve

2019-03-14 01:32发布

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("accounts@greektools.net", 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="accounts@greektools.net">
    <network host="relay-hosting.secureserver.net" port="25" userName="********" password="*********" />
  </smtp>
</mailSettings>

11条回答
淡お忘
2楼-- · 2019-03-14 02:06

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.

查看更多
Lonely孤独者°
3楼-- · 2019-03-14 02:09

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);
    }
查看更多
Deceive 欺骗
4楼-- · 2019-03-14 02:12
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);
}
查看更多
祖国的老花朵
5楼-- · 2019-03-14 02:18

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)
查看更多
爷、活的狠高调
6楼-- · 2019-03-14 02:19

Try below code:

smtp.Host = "relay-hosting.secureserver.net";
smtp.Port = 25;
smtp.Credentials = new System.Net.NetworkCredential("test@yourwebsitedomain.com", "*******");

It worked for me.

查看更多
淡お忘
7楼-- · 2019-03-14 02:20

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.

查看更多
登录 后发表回答