title: SmtpClient cannot send email
body: <p>I try two application, one in java and one in C#. The java application can send email successfully but the C# cannot. Here is the two apps :
  1.Java </p>
  
  <pre><code>    final String username = "myaccount@mydomain";
  final String password = "mypassword";
  String smtpHost = "smtp.mydomain";
  
  Properties props = new Properties();
  props.put("mail.smtp.auth", "true");
  props.put("mail.smtp.host", smtpHost);
  props.put("mail.smtp.port", "465");
  props.put("mail.smtp.socketFactory.port", "465");
  props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  
  Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
      @Override
      protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(username, password);
      }
  });
  
  Message message = new MimeMessage(session);
  message.setFrom(new InternetAddress(username));
  message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(username));
  message.setSubject("Test send email");
  message.setText("Hi you!");
  Transport.send(message);
  </code></pre>
  
  <p>2.C#</p>
  
  <pre><code>    string username = "myaccount@mydomain";
  string password = "mypassword";
  string smtpHost = "smtp.mydomain";
  
  SmtpClient mailClient = new SmtpClient(smtpHost, 465);
  mailClient.Host = smtpHost;
  mailClient.Credentials = new NetworkCredential(username, password);
  mailClient.EnableSsl = true;
  MailMessage message = new MailMessage(username, username, "test send email", "hi u");
  
  mailClient.Send(message);
  </code></pre>
  
  <p>So, what is the mistake i made in C# application? Why it cannot send email?</p>
  
  <p>EDIT:
  I have read this question <a href="https://stackoverflow.com/questions/1011245/how-can-i-send-emails-through-ssl-smtp-with-the-net-framework">How can I send emails through SSL SMTP with the .NET Framework?</a> and it works. The deprecated System.Web.Mail.SmtpMail works but System.Net.Mail.SmtpClient doesn't. Why ?</p>
  
  <p>3.This C# code work fine :</p>
  
  <pre><code>    System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage();
  myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver","smtp.mydomain");
  myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport","465");
  myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing","2");
  myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
  myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "myaccount@mydomain");
  myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "mypassword");
  myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
  myMail.From = "myaccount@mydomain";
  myMail.To = "myaccount@mydomain";
  myMail.Subject = "new code";
  myMail.BodyFormat = System.Web.Mail.MailFormat.Html;
  myMail.Body = "new body";
  System.Web.Mail.SmtpMail.SmtpServer = "smtp.mydomain:465";
  System.Web.Mail.SmtpMail.Send(myMail);
  </code></pre>