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 startStage primaryStage
Scene scene new ScenesendMailPane;
primaryStage.setTitleSend Mail Application";
primaryStage.setScenescene;
primaryStage.show;
primaryStage.setResizabletrue;
Don't touch this method!
private BorderPane sendMailPane
txtMailTo new TextField;
txtMailTo.setPrefColumnCount;
txtMailFrom new TextField;
txtMailFrom.setPrefColumnCount;
txtMailSubject new TextField;
txtMailSubject.setPrefColumnCount;
txtMailBody new TextArea;
txtMailBody.setPrefColumnCount;
txtMailBody.setPrefRowCount;
txtMailStatus new TextField;
txtMailStatus.setPrefColumnCount;
txtMailStatus.setEditablefalse;
Label lblTo new LabelMail To:;
lblTo.setPrefWidth;
Label lblFrom new LabelMail From:";
lblFrom.setPrefWidth;
Label lblSubject new LabelSubject:;
lblSubject.setPrefWidth;
FlowPane tpane new FlowPane;
tpane.setAlignmentPosBASELINELEFT;
tpane.setPaddingnew Insets;
tpane.setStylefxfontweight: bold; fxfontsize: pt;
tpane.getChildrenaddAlllblTo txtMailTo, lblFrom, txtMailFrom, lblSubject, txtMailSubject;
Button btnMailSend generateSendButtonSend Email";
FlowPane cpane new FlowPane;
cpane.setAlignmentPosCENTER;
cpane.setPaddingnew Insets;
cpane.setStylefxfontweight: bold; fxfontsize: pt;
cpane.getChildrenaddAllnew LabelEnter your message below:" txtMailBody, btnMailSend;
Label lblStatus new LabelStatus:;
lblStatus.setPrefWidth;
FlowPane bpane new FlowPane;
bpane.setAlignmentPosBASELINELEFT;
bpane.setPaddingnew Insets;
bpane.setStylefxfontweight: bold; fxfontsize: pt;
bpane.getChildrenaddAlllblStatus txtMailStatus;
BorderPane bp new BorderPane;
bpsetToptpane;
bpsetCentercpane;
bpsetBottombpane;
return bp;
You may change the code in this method to add an event handler
private Button generateSendButtonString caption
Button btnMailSend new Button;
btnMailSend.setTextcaption;
btnMailSend.setOnActione
SMTPProtocol.sendMail
txtMailTo.getText
txtMailFrom.getText
txtMailSubject.getText
txtMailBody.getText;
txtMailStatus.setTextSMTPProtocolgetSendStatus;
;
return btnMailSend;
public static void mainString args
launchargs;
public class SMTPProtocol
public static void sendMailString 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
