I am trying to send email in C#. I wrote 2 pieces of code:
1.
MailMessage mail = new MailMessage();
mail.From = "from_address";
mail.To = "to_address";
mail.Subject = "subject";
mail.BodyFormat = MailFormat.Text;
mail.Body = "body";
SmtpMail.SmtpServer = "smtp.server";
mail.Fields.Clear();
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "userl");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25");
SmtpMail.Send(mail);
/////////////////////////////////////////////////////////////////////////////////////////////
2.
MailMessage mail = new MailMessage("from_address", "to_addressl");
mail.Subject = "subject";
mail.Body = "body";
SmtpClient smtp = new SmtpClient("smtp.server", 25);
smtp.EnableSsl = false;
smtp.Credentials = new System.Net.NetworkCredential("user", "password");
smtp.Send(mail);
I am thrown error:
System.Net.Mail.SmtpException: Failure sending mail. --->
System.Net.WebException: Unable to connect to the remote server --->
System.Net.Sockets.SocketException: A connection attempt failed because the
connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to respond
what is wrong.?
PS
I wrote another application (in borland c++) where I specified the same data
(from/to addresse, server address, user/password) and it works ok