Beispiel #1
0
 // ON SEND MAIL
 int onSendMail() {
   String inBuffer;
   String outBuffer;
   Socket sock;
   SMTPInputStream fromServer;
   SMTPOutputStream toServer;
   int intPort;
   // TEST RECIPIENT ADDRESS it must be at once
   if (reciverMail.getText().length() < 1) {
     infoArea.Println("enter recipient please ...");
     return -1;
   }
   // TEST PORT NUMBER FORMAT and ALERT WHEN NOT 25
   intPort = -1;
   infoArea.Clear();
   infoArea.Println("check port ...");
   try {
     intPort = Integer.valueOf(smtpPort.getText()).intValue();
     if ((intPort < 0) || (intPort > 65356)) {
       infoArea.Println("invalid port ...");
       return -1;
     }
     if (intPort != 25) infoArea.Println("attention port is not 25 ...");
     infoArea.Println("port number is " + smtpPort.getText());
   } catch (NumberFormatException e) {
     infoArea.Println("invalid port ...");
     return -1;
   }
   // CREATE SMTP CONNECTION
   infoArea.Println("connect to server ...");
   try {
     sock = new Socket(smtpServer.getText(), intPort);
   } catch (IOException e) {
     infoArea.Println("unable to connect(SK) ... " + e);
     return -1;
   }
   // CREATE SERVER STREAMS
   // INPUT STREAM
   try {
     fromServer = new SMTPInputStream(sock);
   } catch (IOException e) {
     infoArea.Println("unable to connect(IS) ...");
     return -1;
   }
   // OUTPUT STREAM
   try {
     toServer = new SMTPOutputStream(sock);
   } catch (IOException e) {
     infoArea.Println("unable to connect(OS) ...");
     return -1;
   }
   infoArea.Println("connected ...");
   // Mail Sending
   infoArea.Println("sending mail ...");
   // *******************************************************************
   try {
     int i = doSMTPTransaction(fromServer, toServer);
     if (i == 0) infoArea.Println("complete ...");
     else infoArea.Println("error ...");
   } catch (IOException e) {
     infoArea.Println("error ...");
   }
   // *******************************************************************
   // CLOSE SERVER STREAMS
   // OUTPUT STREAM
   infoArea.Println("disconnect from server ...");
   try {
     toServer.Close();
   } catch (IOException e) {
     infoArea.Println("alert OUTPUT STREAM ...");
   }
   // INPUT STREAM
   try {
     fromServer.Close();
   } catch (IOException e) {
     infoArea.Println("alert INPUT STREAM ...");
   }
   // CLOSE CONNECTION
   try {
     sock.close();
     infoArea.Println("disconnected ...");
   } catch (IOException e) {
     infoArea.Println("unable to disconnect ...");
     return -1;
   }
   return 0;
 }
Beispiel #2
0
 // ON CLEAR MAIL
 void onClearMail() {
   infoArea.Println("clearing mail ...");
   bodyMail.Clear();
 }