views:

54

answers:

3

I have a site hosted on GoDaddy and have an e-mail account set up with my GoDaddy account that uses smtpout.secureserver.net as its outgoing server. I am trying to send an e-mail from my test server, not the actual GoDaddy production server, using this account. My test server is using IIS 7 and is running my ASP.NET MVC site. I use the code below, but every time it executes I get an SmtpException. The InnerText says that it is unable to connect to the remote server. Any thoughts on what I am doing wrong?

MailMessage mailObj = new MailMessage();
        mailObj.From = new MailAddress(this.FromEmail);
        mailObj.Subject = subject;
        mailObj.Body = message;
        mailObj.To.Add(new MailAddress(this.PayerEmail));
        mailObj.IsBodyHtml = true;

        SmtpClient objSmtp = new SmtpClient();
        objSmtp.Host = this.SmtpHost;
        objSmtp.Port = System.Int32.Parse(this.SmtpPort);
        objSmtp.UseDefaultCredentials = false;
        objSmtp.Credentials = new System.Net.NetworkCredential(this.FromEmail, this.FromEmailPassword);
        objSmtp.EnableSsl = false;
        objSmtp.Send(mailObj);

I am sure that the Credentials are correct. Also, the port I am using is 25. Again, the host is smtpout.secureserver.net. I read the following article but couldn't figure out my mistake: http://rtur.net/blog/post/2007/10/12/SMTP-with-GoDaddy.aspx

A: 

More than likely, GoDaddy prevents access to the SMTP server except from servers they host.

You will probably need to find an alternative way to send from your test server.

Andrew Barber
This has been my experience too.
Babak Naffas
They do not block it, you just need to use a specific host for mail relays. See my answer. I send mail from site all the time.
thorkia
@thorkia, have you been able to send mail using relay-hosting.secureserver.net on non-Godaddy hosted sites?
mjh41
+2  A: 

If your test server is hosted on a domestic DSL connection, your ISP could be blocking outbound connections on port 25 - this is quite common as a precaution against infected machines sending reams of spam.

Possible solutions:

  • make the outgoing mailserver configurable in your site, and use your ISP's outgoing mail server when testing
  • use an alternative port - GoDaddy appear to run SMTP on port 80 and SSL-encrypted SMTP on port 465 (although I don't think SmtpClient supports that particular flavour of SSL, so this might not be an option)
  • ask your ISP to unblock the port :)
SimonJ
+1 for mentioning what should have been the other possibility I mentioned in my answer! D'uh! :)
Andrew Barber
relay-hosting.secureserver.net works fine from production. for testing, i went with the configurable mail server option. thanks for the help!
mjh41
You can also use alternative ports that other relays support: http://coderjournal.com/2010/10/how-to-send-smtp-email-through-godaddy/
Nick Berardi
A: 

To send mail on GoDaddy, you need use a specific server: relay-hosting.secureserver.net

That server for SMTP relay is hidden somewhere in the help docs, it took me quite some to find. I hope it helps you.

Here is the code my sites on GoDaddy use to send mail:

mail.From = new MailAddress(fromAddress);
mail.To.Add(toAddress);
mail.Subject = subject;
mail.IsBodyHtml = true;
mail.Body = htmlconvert(bodytext);

//Connect to server and send message.               
SmtpClient smtp = new SmtpClient();
smtp.Host = "relay-hosting.secureserver.net";
smtp.Send(mail);

Here is the actual help article on GoDaddy's own help site:

http://help.godaddy.com/topic/216/article/955

thorkia
I guarantee he *can't* use that server for his e-mail; he isn't sending mail from his GoDaddy host; he's sending it from an external location. `relay-hosting.secureserver.net` is only for use from your GoDaddy hosting, and it doesn't require authentication. (if it allowed outside connections and didn't require auth, it would be useless by now, due to being blacklisted as a spam source)
Andrew Barber
Yes, you are correct. I mis-read the question
thorkia