Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sendMailApp;
- /*
- * Application Code for the Send Mail App
- *
- * Lu Liu
- * CSCI-211 Intermediate Java Programming
- * 4/20/2015
- */
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.PrintWriter;
- import java.net.Socket;
- import java.util.Scanner;
- import javafx.application.Application;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextArea;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.FlowPane;
- import javafx.stage.Stage;
- public class SendMailApp extends Application {
- private TextField txtTo;
- private TextField txtFrom;
- private TextField txtSubject;
- private TextArea txtBody;
- private TextField txtStatus;
- private Button btnSend;
- @Override
- // Override the start method in the Application class
- public void start(Stage primaryStage) {
- txtTo = new TextField();
- txtTo.setPrefColumnCount(25);
- txtFrom = new TextField();
- txtFrom.setPrefColumnCount(25);
- txtSubject = new TextField();
- txtSubject.setPrefColumnCount(25);
- txtBody = new TextArea();
- txtBody.setPrefColumnCount(28);
- txtBody.setPrefRowCount(10);
- btnSend = new Button("Send Email");
- txtStatus = new TextField();
- txtStatus.setPrefColumnCount(25);
- txtStatus.setEditable(false);
- Label lblTo = new Label("Mail To:");
- lblTo.setPrefWidth(90);
- Label lblFrom = new Label("Mail From:");
- lblFrom.setPrefWidth(90);
- Label lblSubject = new Label("Subject:");
- lblSubject.setPrefWidth(90);
- FlowPane tpane = new FlowPane(5, 5);
- tpane.setAlignment(Pos.BASELINE_LEFT);
- tpane.setPadding(new Insets(10, 5, 5, 5));
- tpane.setStyle("-fx-font-weight: bold; -fx-font-size: 12pt");
- tpane.getChildren().addAll(lblTo, txtTo, lblFrom, txtFrom, lblSubject, txtSubject);
- FlowPane cpane = new FlowPane(5, 5);
- cpane.setAlignment(Pos.CENTER);
- cpane.setPadding(new Insets(5, 5, 5, 5));
- cpane.setStyle("-fx-font-weight: bold; -fx-font-size: 12pt");
- cpane.getChildren().addAll(new Label("Enter your message below:"), txtBody, btnSend);
- Label lblStatus = new Label("Status:");
- lblStatus.setPrefWidth(90);
- FlowPane bpane = new FlowPane(5, 5);
- bpane.setAlignment(Pos.BASELINE_LEFT);
- bpane.setPadding(new Insets(5, 5, 10, 5));
- bpane.setStyle("-fx-font-weight: bold; -fx-font-size: 12pt");
- bpane.getChildren().addAll(lblStatus, txtStatus);
- BorderPane bp = new BorderPane();
- bp.setTop(tpane);
- bp.setCenter(cpane);
- bp.setBottom(bpane);
- btnSend.setOnAction(e -> {
- txtStatus.setText("Message Sent Successfully");
- runClient();
- });
- Scene scene = new Scene(bp, 525, 520);
- primaryStage.setTitle("Send Mail Application");
- primaryStage.setScene(scene);
- primaryStage.show();
- primaryStage.setResizable(false);
- }
- /**
- * The main method is only needed for the IDE with limited JavaFX support.
- * Not needed for running from the command line.
- */
- public static void main(String[] args) {
- launch(args);
- }
- public void runClient(){
- Socket client = null;
- PrintWriter output = null;
- Scanner input = null;
- // DataOutputStream output = null;
- // DataInputStream input = null;
- try {
- // Create a socket to connect to the server
- client = new Socket("cs.stcc.edu", 25);
- input.nextLine();
- //HELO
- output = new PrintWriter("HELO cs.stcc.edu");
- System.out.println(input.nextLine());
- output.flush();
- //Mail From
- output.println(txtTo.getText());
- System.out.println(input.nextLine());
- output.flush();
- //Mail To
- output.println(txtFrom.getText());
- System.out.println(input.nextLine());
- output.flush();
- //Message Body
- output.println("DATA");
Add Comment
Please, Sign In to add comment