Saqib A. Azhar
Saqib A. Azhar

Reputation: 1074

Unable to send Email through GoDaddy SMTP

I am working on an ASP .Net MVC website and I've to send email through Godaddy smtp, Previously my site was developed in classic ASP and it was hosted on godaddy's web hosting (then it was working fine) but now I am hosting this site on IIS,

I am using following code to send email but it is not working

MailMessage msg = new MailMessage();
msg.From = new MailAddress(model.From);
msg.To.Add(model.To);
msg.Body = model.Body;
msg.Subject = model.Subject;

SmtpClient smtp = new SmtpClient("relay-hosting.secureserver.net",25);
smtp.Credentials = new NetworkCredentials("support@{myCompanyName}.com",{password});
smtp.EnableSsl  = False;
smtp.Send(msg);

I have also used dedrelay.secureserver.net instead of relay-hosting.secureserver.net host (as mentioned at https://pk.godaddy.com/help/what-is-my-servers-email-relay-server-16601) but both are not working

Upvotes: 3

Views: 9750

Answers (6)

Justice Addico
Justice Addico

Reputation: 94

        string From = "[MyGodaddyEMailAddress]"; //[email protected]
        string FromPassword = "[MyGodaddyMailPassword]";
        try
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(From);
            msg.To.Add("[RecipientEmailAddress]");
            msg.Subject = "[MailSubject]";
            msg.Body = "[MailBody]";
            msg.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient("mail.[domain].com", 587); //eg. mail.mango.com
            smtp.Credentials = new System.Net.NetworkCredential(From, FromPassword);

            smtp.EnableSsl = false;

            // Sending the email
            smtp.Send(msg);
            // destroy the message after sent
            msg.Dispose();
            Console.WriteLine("Message Sent Successfully");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
        Console.ReadKey();

Upvotes: 1

Pr0mis PAtel
Pr0mis PAtel

Reputation: 350

  1. You can try this code

      smtp.Host = "relay-hosting.secureserver.net";    smtp.EnableSsl = false;    smtp.UseDefaultCredentials = false;    smtp.Port = 25;
    

Upvotes: 1

Erik J.
Erik J.

Reputation: 809

Perhaps you should call up to your ISP, here in th Netherlands they mostly block port 25 because of malware and worms that used to send out email. It can be as simple as this. Have you tried telnetting from your local machine to the email server (telnet mailserver.io 25)? If this ends up in a time out you have your answer and the port is either filtered out at your ISP or from their end.

Upvotes: 1

user3163684
user3163684

Reputation: 104

Most SMTP servers are quite restrictive nowadays when it comes to outbound email. I recommend testing the parameters with an email client (or telnet, if you're into that kinda thing) before assuming that there is something wrong with the code. That might also give you an error message that helps debugging.

Some things that come to mind:

  1. The server may check the FROM address against it's database, specifically the user account you use to authenticate. While you can put whatever you want in the header of the email, this field must be your the real address of the authenticated account and only that (no descriptive name).
  2. The server may require the use of TLS encryption, regardless of the port.
  3. Port 25 is quite common, but according to the official RFC mail submission should use port 587. Maybe try that.
  4. It is possible that GoDaddy only allows connections from their own (hosting) servers to these SMTP relays.

Unless the connection fails completely (which would point to no. 4) the server should send some kind of error message at some point. As I wrote above, I would recommend testing/logging the communication, that should provide some insight.

Upvotes: 1

Terry Carmen
Terry Carmen

Reputation: 3886

GoDaddy does not allow relaying through their server unless you are on one of their hosting plans that includes SMTP.

Upvotes: 6

Vikas
Vikas

Reputation: 49

You can set your credentials in webconfig like (for godaddy)

 <system.net>
  <mailSettings>
    <smtp from="your email address">
      <network host="relay-hosting.secureserver.net" port="25" />
    </smtp>
  </mailSettings>
</system.net>

and in c# you can use like

MailMessage message = new MailMessage();
message.From = new MailAddress("your email address");

message.To.Add(new MailAddress("your recipient"));

message.Subject = "your subject";
message.Body = "content of your email";

SmtpClient client = new SmtpClient();
client.Send(message);

It will work

Upvotes: 2

Related Questions