⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e-mailsystem.java

📁 一个完整的email客户端代码 Example program from Chapter 1 Programming Spiders, Bots and Aggregators in Java Co
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	{ 
		if (b) 
			setLocation(50, 50); 
		super.setVisible(b); 
	} 

	/** 
	 * The main function basically just creates a new object, then shows it. 
	 * 
	 * @param args 
	 *            Command line arguments. Not used in this application. 
	 */ 
	static public void main(String args[]) 
	{ 
		(new SendMail()).show(); 
	} 

	/** 
	 * Created by VisualCafe. Sets the window size. 
	 */ 
	public void addNotify() 
	{ 
		// Record the size of the window prior to 
		// calling parents addNotify. 
		Dimension size = getSize(); 

		super.addNotify(); 

		if (frameSizeAdjusted) 
			return; 
		frameSizeAdjusted = true; 

		// Adjust size of frame according to the 
		// insets and menu bar 
		Insets insets = getInsets(); 
		javax.swing.JMenuBar menuBar = getRootPane().getJMenuBar(); 
		int menuBarHeight = 0; 
		if (menuBar != null) 
			menuBarHeight = menuBar.getPreferredSize().height; 
		setSize(insets.left + insets.right + size.width, insets.top 
			+ insets.bottom + size.height + menuBarHeight); 
	} 

	// Used by addNotify 
	boolean frameSizeAdjusted = false; 

	//{{DECLARE_CONTROLS 

	/** 
	 * A label. 
	 */ 
	javax.swing.JLabel JLabel1 = new javax.swing.JLabel(); 

	/** 
	 * A label. 
	 */ 
	javax.swing.JLabel JLabel2 = new javax.swing.JLabel(); 

	/** 
	 * A label. 
	 */ 
	javax.swing.JLabel JLabel3 = new javax.swing.JLabel(); 

	/** 
	 * A label. 
	 */ 
	javax.swing.JLabel JLabel4 = new javax.swing.JLabel(); 

	/** 
	 * Who this message is from. 
	 */ 
	javax.swing.JTextField _from = new javax.swing.JTextField(); 

	/** 
	 * Who this message is to. 
	 */ 
	javax.swing.JTextField _to = new javax.swing.JTextField(); 

	/** 
	 * The subject of this message. 
	 */ 
	javax.swing.JTextField _subject = new javax.swing.JTextField(); 

	/** 
	 * The SMTP server to use to send this message. 
	 */ 
	javax.swing.JTextField _smtp = new javax.swing.JTextField(); 

	/** 
	 * A scroll pane. 
	 */ 
	javax.swing.JScrollPane _scrollPane2 = new javax.swing.JScrollPane(); 

	/** 
	 * The body of this email message. 
	 */ 
	javax.swing.JTextArea _body = new javax.swing.JTextArea(); 

	/** 
	 * The send button. 
	 */ 
	javax.swing.JButton Send = new javax.swing.JButton(); 

	/** 
	 * The cancel button. 
	 */ 
	javax.swing.JButton Cancel = new javax.swing.JButton(); 

	/** 
	 * A scroll pain. 
	 */ 
	javax.swing.JScrollPane _scrollPane = new javax.swing.JScrollPane(); 

	/** 
	 * The output area. Server messages are displayed here. 
	 */ 
	javax.swing.JList _output = new javax.swing.JList(); 

	//}} 

	/** 
	 * The list of items added to the output list box. 
	 */ 
	javax.swing.DefaultListModel _model = new javax.swing.DefaultListModel(); 

	/** 
	 * Input from the socket. 
	 */ 
	java.io.BufferedReader _in; 

	/** 
	 * Output to the socket. 
	 */ 
	java.io.PrintWriter _out; 

	//{{DECLARE_MENUS 
	//}} 

	/** 
	 * Internal class created by VisualCafe to route the events to the correct 
	 * functions. 
	 * 
	 * @author VisualCafe 
	 * @version 1.0 
	 */ 
	class SymAction implements java.awt.event.ActionListener 
	{ 

		/** 
		 * Route the event to the correction method. 
		 * 
		 * @param event 
		 *            The event. 
		 */ 
		public void actionPerformed(java.awt.event.ActionEvent event) 
		{ 
			Object object = event.getSource(); 
			if (object == Send) 
				Send_actionPerformed(event); 
			else if (object == Cancel) 
				Cancel_actionPerformed(event); 
		} 
	} 

	/** 
	 * Called to actually send a string of text to the socket. This method makes 
	 * note of the text sent and the response in the JList output box. Pass a 
	 * null value to simply wait for a response. 
	 * 
	 * @param s 
	 *            A string to be sent to the socket. null to just wait for a 
	 *            response. 
	 * @exception java.io.IOException 
	 */ 
	protected void send(String s) throws java.io.IOException 
	{ 
		// Send the SMTP command 
		if (s != null) 
		{ 
			_model.addElement("C:" + s); 
			_out.println(s); 
			_out.flush(); 
		} 
		// Wait for the response 
		String line = _in.readLine(); 
		if (line != null) 
		{ 
			_model.addElement("S:" + line); 
		} 
	} 

	/** 
	 * Called when the send button is clicked. Actually sends the mail message. 
	 * 
	 * @param event 
	 *            The event. 
	 */ 
	void Send_actionPerformed(java.awt.event.ActionEvent event) 
	{ 
		try 
		{ 

			java.net.Socket s = new java.net.Socket(_smtp.getText(), 25); 
			_out = new java.io.PrintWriter(s.getOutputStream()); 
			_in = new java.io.BufferedReader(new java.io.InputStreamReader(s 
				.getInputStream())); 

			send(null); 
			send("HELO " + java.net.InetAddress.getLocalHost().getHostName()); 
			send("MAIL FROM: " + _from.getText());
			send("RCPT TO: " + _to.getText()); 
			send("DATA"); 
			_out.println("Subject:" + _subject.getText()); 
			_out.println(_body.getText()); 
			send("."); 
			s.close(); 

		} 
		catch (Exception e) 
		{ 
			_model.addElement("Error: " + e); 
		} 

	} 

	/** 
	 * Called when cancel is clicked. End the application. 
	 * 
	 * @param event 
	 *            The event. 
	 */ 
	void Cancel_actionPerformed(java.awt.event.ActionEvent event) 
	{ 
		System.exit(0); 

	} 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -