Unable to connect to remote server

I have a C# program that runs on my laptop and send an email, using my remote website to relay the email.  But when I run the same program from a Virtual Private Server of mine, I get the error: Unable to Connect to Remote Server.

Dos anyone have any idea about what could be the problem?  I could include the source code, but suspect the problem lies in the configuration or environment, versus the code.

Any idea of what to check?

newbiewebSr. Software EngineerAsked:
Who is Participating?
can you telnet from the machine to your mail server on port 25?

telnet mail.host.com 25

Can the virtual server route to the internet?
newbiewebSr. Software EngineerAuthor Commented:
Here is the code:

        private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
            // Get the unique identifier for this asynchronous operation.
            MailMessage eMailMessage = (MailMessage)e.UserState;
            if (e.Cancelled)
                //Console.WriteLine("[{0}] Send canceled.", token);
            if (e.Error != null)
                //Console.WriteLine("[{0}] {1}", token, e.Error.ToString());
                string emailAddress = (string)eMailMessage.To[0].Address;

        public void Send()
            // Command line argument must the the SMTP host.
            SmtpClient client = new SmtpClient(Handles.SMTPServer);

            NetworkCredential nc = new NetworkCredential(Handles.Username, Handles.Password);
            client.UseDefaultCredentials = false;
            client.Credentials = nc;

            // Specify the e-mail sender.
            // Create a mailing address that includes a UTF8 character
            // in the display name.
            MailAddress from = new MailAddress(handles.FromEmail, handles.FromFirstName + " " + handles.FromLastName, System.Text.Encoding.UTF8);

            // Set destinations for the e-mail message.
            MailAddress to = new MailAddress(contact.EmailAddress);
            // Specify the message content.
            MailMessage message = new MailMessage(from, to);
            message.Body = "";//"ApplicationPath=" + HttpContext.Current.Request.ApplicationPath;
            // Include some non-ASCII characters in body and subject.
            message.Body += Environment.NewLine;
            message.BodyEncoding =  System.Text.Encoding.UTF8;
            message.Subject = "test message from " + handles.Preferences.MachineName;
            message.SubjectEncoding = System.Text.Encoding.UTF8;
            // Set the method that is called back when the send operation ends.
            client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
            // The userState can be any object that allows your callback
            // method to identify this send operation.
            // For this example, the userToken is a string constant.
            //Object userState = this;
            Object userState = message;
            client.SendAsync(message, userState);
Bob LearnedCommented:
Yeah, do you need to go through a firewall or proxy?

I think your Virtual Private Server is having permissions issue in the network.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.