计算机网络自顶向下方法作业2:邮件客户机在这个作业中,你将用java开发一个具有以下特点的用户客户代理为发送者提供一个图像界面,其中具有用于本地邮件服务器的以下字段:发送者的电子邮箱地址,接受者的电子邮箱地址,保温主题以及报文本身。邮件客户机与本地邮件服务器之间创建一个TCP连接。想本地服务器发送SMTP命令,从本地邮件服务器接受与处理SMTP命令。无图无真相,先上效果图:邮箱收到信件如下:SendFrame.java代码:packagemail;importjava.awt.BorderLayout;importjava.awt.EventQueue;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.border.EmptyBorder;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JTextField;importjavax.swing.JTabbedPane;importjavax.swing.JTextPane;importjavax.swing.JTextArea;importjavax.swing.JButton;importjavax.swing.JScrollPane;importjava.awt.Panel;importjava.awt.ScrollPane;importjava.awt.TextArea;importjava.awt.event.ActionListener;importjava.awt.event.ActionEvent;importjava.io.DataOutputStream;importjava.io.IOException;importjava.net.Inet4Address;importjava.net.Socket;importjava.net.UnknownHostException;importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.IOException;importjava.io.InputStreamReader;importjava.io.OutputStreamWriter;importjava.net.Socket;importjava.net.SocketException;importjava.net.UnknownHostException;importjava.util.StringTokenizer;importsun.misc.BASE64Encoder;publicclassSendFrameextendsJFrame{privateJPanelcontentPane;privateJTextFieldtxt_From;privateJTextFieldtxt_To;privateJTextFieldtext_Subject;privateJFramethisFrame;/***Launchtheapplication.*/publicstaticvoidmain(String[]args){EventQueue.invokeLater(newRunnable(){publicvoidrun(){try{SendFrameframe=newSendFrame();frame.setVisible(true);}catch(Exceptione){e.printStackTrace();}}});}/***Createtheframe.*/publicSendFrame(){thisFrame=this;setTitle(JavaMailclient);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100,100,450,328);contentPane=newJPanel();contentPane.setBorder(newEmptyBorder(5,5,5,5));setContentPane(contentPane);contentPane.setLayout(null);JLabellblFrom=newJLabel(from:);lblFrom.setBounds(10,10,54,22);contentPane.add(lblFrom);JLabellblTo=newJLabel(To:);lblTo.setBounds(10,42,42,22);contentPane.add(lblTo);JLabellblSubject=newJLabel(Subject:);lblSubject.setBounds(10,74,54,22);contentPane.add(lblSubject);txt_From=newJTextField();txt_From.setEditable(false);txt_From.setText(woiandroid@163.com);txt_From.setBounds(49,11,383,21);contentPane.add(txt_From);txt_From.setColumns(10);txt_To=newJTextField();txt_To.setText(674496813@qq.com);txt_To.setColumns(10);txt_To.setBounds(49,42,383,21);contentPane.add(txt_To);text_Subject=newJTextField();text_Subject.setText(作业2:邮件客户机);text_Subject.setColumns(10);text_Subject.setBounds(66,73,366,21);contentPane.add(text_Subject);JLabellblMassage=newJLabel(Massage:);lblMassage.setBounds(10,101,64,15);contentPane.add(lblMassage);JButtonbtnQuit=newJButton(Quit);btnQuit.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){thisFrame.dispose();}});btnQuit.setBounds(295,271,137,23);contentPane.add(btnQuit);JScrollPanescrollPane=newJScrollPane();scrollPane.setBounds(10,229,422,-101);contentPane.add(scrollPane);Panelpanel=newPanel();panel.setBounds(10,115,422,156);contentPane.add(panel);panel.setLayout(null);ScrollPanescrollPane_1=newScrollPane();scrollPane_1.setBounds(0,0,422,156);panel.add(scrollPane_1);finalTextAreaSend_TextArea=newTextArea();Send_TextArea.setText(你好!我是计Y096的刘展鹏);Send_TextArea.setBounds(0,0,440,170);scrollPane_1.add(Send_TextArea);JButtonbtnSend=newJButton(Send);btnSend.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){Stringtxtfrom=txt_From.getText();Stringtxtto=txt_To.getText();Stringtxtsubject=text_Subject.getText();Stringsendtextarea=Send_TextArea.getText();try{MailMessagemessage=newMailMessage();message.setFrom(txtfrom);//发件人message.setTo(txtto);//收件人Stringserver=smtp.163.com;//邮件服务器smtp.qq.commessage.setSubject(txtsubject);//邮件主题message.setContent(sendtextarea);//邮件内容message.setDatafrom(txtfrom);//发件人,在邮件的发件人栏目中显示message.setDatato(txtto);//收件人,在邮件的收件人栏目中显示message.setUser(woiandroid);//登陆邮箱的用户名message.setPassword(3838438);//登陆邮箱的密码SendFramesmtp=newSendFrame(server,25);booleanflag;flag=smtp.sendMail(message,server);if(flag){JOptionPane.showMessageDialog(null,信息已成功发送!,提示,JOptionPane.INFORMATION_MESSAGE);}else{JOptionPane.showMessageDialog(null,邮件发送失败!,提示,JOptionPane.INFORMATION_MESSAGE);}//System.out.println(iuhfihulaeihba);}catch(UnknownHostExceptione1){//TODOAuto-generatedcatchblocke1.printStackTrace();}catch(IOExceptione1){//TODOAuto-generatedcatchblocke1.printStackTrace();}//JOptionPane.showMessageDialog(null,信息已成功发送!,提示,JOptionPane.INFORMATION_MESSAGE);//System.out.println(txtfrom+\n+txtto+\n+txtsubject+\n+sendtextarea);}});btnSend.setBounds(10,271,144,23);contentPane.add(btnSend);JButtonbtnClear=newJButton(Clear);btnClear.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){txt_To.setText();text_Subject.setText();Send_TextArea.setText();JOptionPane.showMessageDialog(null,信息删除成功!,提示,JOptionPane.INFORMATION_MESSAGE);}});btnClear.setBounds(149,271,150,23);contentPane.add(btnClear);}privatebooleandebug=true;BASE64Encoderencode