2

What am I doing wrong? Im trying to send a email using c# with GoDaddy webhost.

SmtpClient client = new SmtpClient("relay-hosting.secureserver.net", 465);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("emailGODADDY", "password");

MailMessage message = new MailMessage("emailGODADDY", "otherEmail");
message.Subject = txtSubject.Text;
message.Body = txtContent.Value;

client.Send(message);
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
João Paulo
  • 6,300
  • 4
  • 51
  • 80
  • 1
    What happens? Error message? Just doesn't arrive? Did you check the spam folder? – Eric J. Jun 14 '12 at 01:45
  • At ...MailMessage("emailGODADDY",...) I assume you actually have a valid* email address entered (*valid meaning it ends with a TLD like .com, .org, and so forth)? Are you getting a specific error, or is it just timing out? – Patrick Pitre Jun 14 '12 at 01:51
  • -> the email is valid: info@domain.com.br (tested in windows live mail); -> nothing in spam folder... -> MSG: Unable to read data from the transport connection: net_io_connectionclosed. – João Paulo Jun 14 '12 at 01:59
  • Get outlook configuration settings from godaddy and the configure your SMTP client object by those settings accordingly. – Niranjan Singh Jun 14 '12 at 02:12
  • See this similar question: http://stackoverflow.com/questions/2209617/smtpclient-failure-sending-mail – Eric J. Jun 14 '12 at 03:18

4 Answers4

9

With a shared hosting account with Go Daddy you need to send emails on port 25 not port 465. Furthermore, relay-hosting.secureserver.net does not need you to authenticate with a username and password when you are sending from your hosting account.

Mike_GoDaddy
  • 1,121
  • 1
  • 7
  • 9
2

OKAY! I have figured this out.

Wow, I've spent so much time trying to get this up and running. I have Economy Windows Hosting with Plesk (Shared), with a single Office365 email account. I learned the hard way that you can't create a SMTP client that connects to smtp.office365.com, as port 587 is blocked for this shared hosting package. TXT records, SPF records don't help either. Lots of wasted time.

But alas, here's exactly what worked for me. I added the following to my web.config, though I think you can build the same info into your SMTP client object. Still, this works fine. Whatever.

<system.net>
  <mailSettings>
    <smtp from="noreply@MyDomain.com">        
      <network host="relay-hosting.secureserver.net" port="25" />        
    </smtp>
  </mailSettings>
</system.net>

In my code behind, I made sure that the FROM address used in the MailMessage exactly matched the FROM value within the web.config. Does this really matter? Not sure, but they match, and it works. Whatever.

The FROM address (noreply@) does NOT exist as an email, nor is it an alias, etc. It's just something from the same domain where the website is hosted.

My TO address is retrieved from within the web.config (AppSettings["SendTo"]). This is my real email address that lives on this domain (my Office365 email address). I'm not sure if you can send an email to something outside the domain, as I haven't tested.

... obviously the MailMessage (msg) is not complete ...

msg.To.Add(new MailAddress(ConfigurationManager.AppSettings["SendTo"].ToString()));
msg.From = new MailAddress("noreply@MyDomain.com");


var smtp = new SmtpClient 
{       
 // nothing is needed here  
};
smtp.Send(msg);

Create your client and send the message!

YAY! I had to list the noreply@ email as not spam, but now it's arriving as expected. Remember, you only have a limited number of relay emails per day, so use them wisely! Hope this helps!

RichieMN
  • 905
  • 1
  • 12
  • 33
1

Each smtp server has own credentials which is not same with other.

According to microsoft client.UseDefaultCredentials should not be used when possible.

You can try by omitting this line of code.....

client.UseDefaultCredentials = false;

If this will not work then try with

client.EnableSsl = false;

Because some server do not use secure connection.

You can check with this code also

client.DeliveryMethod = SmtpDeliveryMethod.Network;
Md Kamruzzaman Sarker
  • 2,387
  • 3
  • 22
  • 38
1

Just comment out below line than it will work fine

//client.EnableSsl = false;

also use Port 25.

Kaif Ahmed
  • 11
  • 2