Question: Create a simple program on java that can send an email to anyone using the SMTP protocol. The first code is the starter code, only

Create a simple program on java that can send an email to anyone using the SMTP protocol. The first code is the starter code, only change what labeled to be changed on this one, the second code is what to edit, use any server you want to have the program work.
_________________
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 txtMailTo;
private TextField txtMailFrom;
private TextField txtMailSubject;
private TextArea txtMailBody;
private TextField txtMailStatus;
// Don't touch this method!
@Override
public void start(Stage primaryStage){
Scene scene = new Scene(sendMailPane(),525,520);
primaryStage.setTitle("Send Mail Application");
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setResizable(true);
}
// Don't touch this method!
private BorderPane sendMailPane(){
txtMailTo = new TextField();
txtMailTo.setPrefColumnCount(25);
txtMailFrom = new TextField();
txtMailFrom.setPrefColumnCount(25);
txtMailSubject = new TextField();
txtMailSubject.setPrefColumnCount(25);
txtMailBody = new TextArea();
txtMailBody.setPrefColumnCount(28);
txtMailBody.setPrefRowCount(10);
txtMailStatus = new TextField();
txtMailStatus.setPrefColumnCount(25);
txtMailStatus.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, txtMailTo, lblFrom, txtMailFrom, lblSubject, txtMailSubject);
Button btnMailSend = generateSendButton("Send Email");
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:"), txtMailBody, btnMailSend);
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, txtMailStatus);
BorderPane bp = new BorderPane();
bp.setTop(tpane);
bp.setCenter(cpane);
bp.setBottom(bpane);
return bp;
}
// You may change the code in this method to add an event handler
private Button generateSendButton(String caption){
Button btnMailSend = new Button();
btnMailSend.setText(caption);
btnMailSend.setOnAction(e ->{
SMTPProtocol.sendMail(
txtMailTo.getText(),
txtMailFrom.getText(),
txtMailSubject.getText(),
txtMailBody.getText());
txtMailStatus.setText(SMTPProtocol.getSendStatus());
});
return btnMailSend;
}
public static void main(String[] args){
launch(args);
}
}
______________________________
public class SMTPProtocol {
public static void sendMail(String mailTo, String mailFrom, String mailSubject,
String mailBody){
}
public static String getSendStatus(){
return "Mail Sent.";
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!