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

📄 china_net_smtp.java

📁 一个相当不错的smtp程序
💻 JAVA
字号:
//-----------------------------------------------------------------------// File Name: china_net_smtp// Function:  The Java Program is about Email// last modified: 2000-02-24// Version : 1.0// Author : ning--ly//-----------------------------------------------------------------------import java.io.*;import sun.net.*;import sun.net.ftp.*;import sun.net.smtp.*;import java.net.*;import java.util.*;// -----------------------------------------------------------------------// class nSmtp   // -----------------------------------------------------------------------class   china_net_smtp   {   	   public static DataInputStream	serverInput= null;   public static PrintStream	serverOutput= null;      public static String EmailServer;      public static String Hello;      public static String Receiver;   public static String Other;      public static String Sender;      public static String Subject;	         public static String Datas;      public static Socket smtp= null;         public static String message = null;      public static boolean error = false;      StringBuffer sb;   int i=0;   int c;   String fnm;      //static TelnetInputStream tis;   //static TelnetOutputStream tos;   	   public void setEmailServer(String emailServer)   {	   EmailServer=emailServer;		      }      public void hello(String helo,int type)   {	   try{			 	   if(type==0)	   {			String loc=InetAddress.getLocalHost().getHostName();			this.Hello=loc;   	   }	   else		   this.Hello=helo;	   }catch(IOException e){		   error=true;		   message=e.toString();		   System.out.println(e.toString());		   System.out.println(0);							  			   	   }		    }            public void cc(String other_mail)   {	   Other=other_mail;   }         public void from(String sender)   {	   Sender=sender;   }      public void to(String receiver)   {	   Receiver=receiver;   }   public void data(String dat)   {	   Datas=dat;   }   public void subject(String sub)   {	   Subject=sub;   }   public void open()	      {	  String code;       try         {          		  System.out.println("begin to link email_server: ");		  System.out.println(EmailServer);		  			           smtp =new Socket(EmailServer,25);                 serverOutput =new PrintStream(new BufferedOutputStream(smtp.getOutputStream()),true);         serverInput =new DataInputStream(smtp.getInputStream());		 		 System.out.println(smtp.toString());		 	  }catch(IOException e){		  	   System.out.print(e);	   error=true;	   message=e.toString();		   	   System.exit(0);			  };   }      public void exec()   {	   try{         		 int j;		 		 //open();		 		 		 //From: "lyning" <ning-ly@genuis.com.cn>         // To: <ning-ly@genius.com.cn>			 		 	 		 send("HELO "+ Hello);		 		 receive();		 receive();		 		 send("MAIL FROM: "+ Sender);		 		 receive();		 		 send("RCPT TO: "+ Receiver);		 		 receive();		 		 send("DATA");		 		 receive();		 		 send("From: <"+ Sender+">\r");		 		 send("To: "+ "<"+ Receiver+">\r");	  		 		 if(Other.length()!=0)			 send("Cc: "+ Other+"\r");	  					 		 send("Subject: "+ Subject+ "\r");		 		 //send("Subject: JAVA EMAIL");		 		// send("From: <"+ Sender+">\r\n");		 		 //send("To: "+ Receiver + "<"+ Receiver+">\r\n");	  		 	     //send("Message-ID: <000901bf7c65$a0392ac0$2565a8c0@ningly>\r\n");	     //send("Date: Mon, 21 Feb 2000 20:17:32 +0800\r\n");	  		 		 send("\r\n"+ Datas+"\r\n.\r\n");	 	 		 receive();		   	          System.out.println("Exec Success!");		 	  }catch(IOException e){	System.out.print(e);	System.exit(0);			  };	       };       public static void send(String str) throws IOException   {	   serverOutput.print(str+"\r\n");	   serverOutput.flush();	   	   System.out.println("Send: "+ str);		      }      public static void receive() throws IOException   {	   String tmp=serverInput.readLine();	   			   System.out.println("Response: "+ tmp);		      }	    		 	 public void Close()	 {		 try{	     	 		 System.out.println("BEGIN QUIT");		 		 send("QUIT");		 	     if(smtp!=null) smtp.close();		          smtp= null;		          serverOutput= null;		          serverInput= null;                  } catch(IOException e) {                 System.out.println("ioexc e"+e);		 System.exit(0);			          }      	 }	}	// -----------------------------------------------------------------------// nSmtpClient : // -----------------------------------------------------------------------/*class nSmtpClient{	public static SmtpClient smtp;		public static PrintStream ps=null;			public void exec()	{		try{					System.out.println("111");				smtp=new SmtpClient("EmailTest");				System.out.println("222");				smtp.openServer("192.168.100.2",25);				//ps=new PrintStream(new BufferedOutputStream(smtp.serverOutput,2000));				smtp.from("ning-ly@genius.com.cn");		smtp.to("ning-ly@genius.com.cn");				//smtp.startMessage("I am email tester");				smtp.sendServer("HELP\r\n");						System.out.println(smtp.getResponseString());					smtp.sendServer("DATA\r\n");				smtp.sendServer("SUBJECT: TEST");			    	smtp.sendServer("\r\nTHIS IS email data \r\n.");						System.out.println(smtp.getResponseString());					smtp.sendServer("QUIT");								smtp.closeServer();		}catch(IOException e){						System.out.println(e);		}				}}*/// -----------------------------------------------------------------------// Main: // -----------------------------------------------------------------------/*class nemail7{		public static void main(String args[])	{						System.out.println("\n ---------------------------------------------------------------------------\n");				System.out.println("            Welcome you to use Email TOOLS (1.0) ");				System.out.println("\n ---------------------------------------------------------------------------\n");			//	nSmtpClient smtpClient=new nSmtpClient();			//	smtpClient.exec();							nemail_config nfg=new nemail_config();				nfg.read_config("email_config.txt");				if(nfg.err == true)		{			System.out.println("ftp config err!");						System.exit(0);						}        					System.out.println(nfg.ip);										nEmail nfc=new nEmail();						 nfc.setEmailServer("192.168.100.2");					 nfc.hello("",0);		 		 		 nfc.from("nly@genius.com.cn");		 		 nfc.to(nfg.email1);		 		 nfc.data(".ad .邮件测试程序 v7 this a test .java....email \r\n this line 2 .");		 		 nfc.subject("Email Java6");		 		 nfc.cc(nfg.email2+ "," + nfg.email3);		 		 		 			 		 nfc.open();		 			 		 nfc.exec();		 		 nfc.to(nfg.email2);		 		 nfc.exec();		 		 nfc.to(nfg.email3);		 		 		 nfc.exec();		 		 nfc.Close();		  						System.out.println("-------------------------------------------");		System.out.println("      Thank you to use the software!       ");		System.out.println("-------------------------------------------");							System.exit(0);		}}*///=======================================================================//						End of Ftp Upload Program//======================================================================= 				  

⌨️ 快捷键说明

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