title: send mail to Gmail account
body: <p>I am sending mail from my Java app to Gmail Account. I had used the Java Mail API and it worked fine. But is it possible to send an e-mail without using the mail API in java?</p>
  
  <p>I mean just by using sockets:</p>
  
  <pre><code>public class Main {
    public static void main(String[] args) throws Exception {
      String host = "smtp.gmail.com";
      int port = 465;
      String from = "sh2rpzain@gmail.com";
      String toAddr = "sharpzian@gmail.com";
  
  
      Socket servSocket = new Socket(host, port);
      DataOutputStream os = new DataOutputStream(servSocket.getOutputStream());
      DataInputStream is = new DataInputStream(servSocket.getInputStream());
  
      if (servSocket != null &amp;&amp; os != null &amp;&amp; is != null) {
        os.writeBytes("HELO\r\n");
        os.writeBytes("MAIL From:" + from + " \r\n");
        os.writeBytes("RCPT To:" + toAddr + "\r\n");
        os.writeBytes("DATA\r\n");
        os.writeBytes("X-Mailer: Java\r\n");
        os.writeBytes("DATE: " + DateFormat.getDateInstance(DateFormat.FULL, 
                                     Locale.US).format(new Date()) + "\r\n");
        os.writeBytes("From:" + from + "\r\n");
        os.writeBytes("To:" + toAddr + "\r\n");
      }
  
      os.writeBytes("Subject:\r\n");
      os.writeBytes("body\r\n");
      os.writeBytes("\r\n.\r\n");
      os.writeBytes("QUIT\r\n");
      String responseline;
      while ((responseline = is.readUTF()) != null) { 
        if (responseline.indexOf("Ok") != -1)
          break;
      }
    }
  }
  </code></pre>
  
  <p>But it is not working, it doesn't send out the mail. Can anyone tell me what could be the problem?</p>