Unable to connect to remote server

Posted on 2007-10-18
Last Modified: 2013-12-18
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?

Question by:newbieweb

    Author Comment

    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);
    LVL 4

    Accepted Solution

    can you telnet from the machine to your mail server on port 25?

    telnet 25

    Can the virtual server route to the internet?
    LVL 96

    Assisted Solution

    by:Bob Learned
    Yeah, do you need to go through a firewall or proxy?

    LVL 1

    Assisted Solution

    I think your Virtual Private Server is having permissions issue in the network.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
    In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now