Link to home
Start Free TrialLog in
Avatar of curiouswebster
curiouswebsterFlag for United States of America

asked on

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
Avatar of curiouswebster
curiouswebster
Flag of United States of America image

ASKER

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);
        }
ASKER CERTIFIED SOLUTION
Avatar of redcelltech
redcelltech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial