Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29748

"Unable to connect to the remote server" Error

$
0
0

I'm trying to send an email from my website.

this is my code:

public string SendEmail()
    {
    string sMessage;
    SmtpClient smtpClient = new SmtpClient("mail.test.com",25);
    MailMessage message = new MailMessage();
    try
        {
         smtpClient.Credentials = new System.Net.NetworkCredential("web", "test1234", "myDomain");
         MailAddress fromAddress = new MailAddress("web@test.com", "web");

         message.From = fromAddress;
         message.To.Add("test@gmail.com"); 
         message.Subject = "test";
         message.Body = "TEST";
         message.IsBodyHtml = true;
         smtpClient.EnableSsl = false; 
         smtpClient.Send(message);
         sMessage = "Email sent.";
        }
        catch (Exception ex)
        {
            sMessage = "Coudn't send the message!\n " + ex.Message;
        }
        return "";
    }

But I'm getting the following error:

"Unable to connect to the remote server"

The data (host name, port, credentials) is correct, I checked it in a few SMTP checkers (for ex this one) and it worked fine.

I tried everything I found online:

smtpClient.UseDefaultCredentials = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

And different ports but nothing helped, I keep getting the error.

What am I doing something wrong? Am I missing something?


Viewing all articles
Browse latest Browse all 29748

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>