how can i send email using j2me midlet

97 Views Asked by At

hi all i have been trying to write the a j2me email client code which enables the midlet to send an email into my account but i faced the following error "Must issue a STARTTLS Command first" here is the code and i included the result shown on emulator with the image and i got the starting source code from [oracle java me website][1]

       
      
 
      try {
    //smtpServerAddress=smtp.gmail.com
         sc = (SocketConnection)Connector.open("socket://"+smtpServerAddress+":587");
         is = sc.openInputStream();
         os = sc.openOutputStream();

         os.write(("HELO there" + "\r\n").getBytes()); 
         os.write(("MAIL FROM: "+ from +"\r\n").getBytes());
         os.write(("RCPT TO: "+ to + "\r\n").getBytes());
         os.write("DATA\r\n".getBytes());
         
         os.write(("From: "+from+"\r\n").getBytes());
         os.write(("To: "+to+"\r\n").getBytes());
         os.write(("Subject: "+subject+"\r\n").getBytes());
         os.write((msg+"\r\n").getBytes()); // message body
         os.write(".\r\n".getBytes());
         os.write("QUIT\r\n".getBytes());

         // debug
         StringBuffer sb = new StringBuffer();
         int c = 0;
         while (((c = is.read()) != -1) ) {
            sb.append((char) c);
         }
         si.setText("SMTP server response - " + sb.toString());      

      } catch(IOException e) {}```



[the image shows the output result on emulator][2]


  [1]: https://www.oracle.com/technical-resources/articles/javame/lowlevel-networkprogramming-midp20.html
  [2]: https://i.stack.imgur.com/YJ0Y0.png
0

There are 0 best solutions below