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?

Thanks,
newbieweb
newbiewebSr. Software EngineerAsked:
Who is Participating?
 
redcelltechCommented:
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?
0
 
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());
            }
            else
            {
                string emailAddress = (string)eMailMessage.To[0].Address;
                eMailMessage.Dispose();
            }
        }

        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);
        }
0
 
Bob LearnedCommented:
Yeah, do you need to go through a firewall or proxy?

Bob
0
 
pothireddysunilCommented:
I think your Virtual Private Server is having permissions issue in the network.
0
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.