Exemple #1
0
  SMTPprotocol() {
    super("SMTP Protocol Test v.1.0 by Tair Abdurman");
    setBackground(Color.lightGray);
    setLayout(new FlowLayout());
    // ******************************************************************
    smtpServer = new TextField("smtp.blueyonder.co.uk", 50);
    smtpPort = new TextField("25", 10);
    senderMail = new TextField("*****@*****.**", 80);
    reciverMail = new TextField("*****@*****.**", 0);
    ccMail = new TextField("", 80);
    bccMail = new TextField("", 80);
    subjectMail = new TextField("SMTP deneme", 80);

    add(new Label("SMTP Server:"));
    add(smtpServer);
    add(new Label("SMTP Port:"));
    add(smtpPort);

    add(new Label("From:    "));
    add(senderMail);
    add(new Label("To  :    "));
    add(reciverMail);
    add(new Label("Cc  :    "));
    add(ccMail);
    add(new Label("Bcc :    "));
    add(bccMail);
    add(new Label("Subject :"));
    add(subjectMail);

    add(new Label("Content :               "));
    bodyMail = new InfoBox(5, 90);
    bodyMail.setEditable(true);

    add(bodyMail);

    sendMail = new Button("send");
    clearMail = new Button("clear");
    quitProgram = new Button("quit");

    add(sendMail);
    add(clearMail);
    add(quitProgram);

    infoArea = new InfoBox(4, 90);
    add(infoArea);

    // ******************************************************************
    resize(700, 450);
    show();
    infoArea.Println("ready ...");
  }
Exemple #2
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;
 }
Exemple #3
0
 // ON CLEAR MAIL
 void onClearMail() {
   infoArea.Println("clearing mail ...");
   bodyMail.Clear();
 }
Exemple #4
0
 // ON QUIT PROGRAM
 void onQuit() {
   infoArea.Println("quit programm ...");
   System.exit(0);
 }