www.pudn.com > srmail.rar > send.java


import org.apache.crimson.parser.Resolver; 
import org.eclipse.swt.SWT; 
import org.eclipse.swt.events.SelectionAdapter; 
import org.eclipse.swt.events.SelectionEvent; 
import org.eclipse.swt.widgets.Button; 
import org.eclipse.swt.widgets.CoolBar; 
import javax.mail.*; 
import javax.mail.internet.MimeMessage; 
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeBodyPart; 
import javax.mail.internet.MimeMultipart; 
import javax.print.DocFlavor.READER; 
import javax.activation.FileDataSource; 
import javax.activation.DataSource; 
import javax.activation.DataHandler; 
import java.util.Properties; 
import java.util.Date; 
import java.util.StringTokenizer; 
import java.io.BufferedReader; 
import java.io.BufferedWriter; 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileReader; 
import java.io.FileWriter; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.io.PrintWriter; 
import java.io.Reader; 
 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.FileDialog; 
import org.eclipse.swt.widgets.Label; 
import org.eclipse.swt.widgets.MessageBox; 
import org.eclipse.swt.widgets.Shell; 
import org.eclipse.swt.widgets.Text; 
import com.swtdesigner.SWTResourceManager; 
 
 
public class send extends Thread { 
	 
	Shell shell; 
	private static Text text_3; 
	private static Text text_2; 
	private static Text text_1; 
	private static Text text; 
    private static final String[] FILTER_NAMES = {                                      //定义 
	      "OpenOffice.org Spreadsheet Files (*.sxc)",                                    
	      "Microsoft Excel Spreadsheet Files (*.xls)",                                  //浏览 
	      "Comma Separated Values Files (*.csv)", "All Files (*.*)"};                                                                                                   //文件 
	  // These filter extensions are used to filter which files are displayed.               
	private static final String[] FILTER_EXTS = { "*.sxc", "*.xls", "*.csv", "*.*"};  //类型 
public send(){    
		 
 
		    shell = new Shell();  
		    createContents(shell); 
			shell.open(); 
} 
public void createContents(Shell shell) { 
		shell.setText("sendmail"); 
		shell.setSize(489, 429); 
 
		final Label label = new Label(shell, SWT.NONE); 
		label.setFont(SWTResourceManager.getFont("", 16, SWT.NONE)); 
		label.setText("收信人:"); 
		label.setBounds(5, 10, 79, 35); 
 
		final Label label_1 = new Label(shell, SWT.NONE); 
		label_1.setFont(SWTResourceManager.getFont("", 16, SWT.NONE)); 
		label_1.setText("主题:"); 
		label_1.setBounds(5, 55, 66, 40); 
 
		text = new Text(shell, SWT.BORDER); 
		text.setFont(SWTResourceManager.getFont("", 16, SWT.NONE)); 
		text.setBounds(90, 0, 384, 35); 
 
		text_1 = new Text(shell, SWT.BORDER); 
		text_1.setFont(SWTResourceManager.getFont("", 16, SWT.NONE)); 
		text_1.setBounds(90, 50, 381, 35); 
 
		final Label label_2 = new Label(shell, SWT.NONE); 
		label_2.setFont(SWTResourceManager.getFont("", 16, SWT.NONE)); 
		label_2.setText("附件:"); 
		label_2.setBounds(7, 100, 65, 30); 
 
		text_2 = new Text(shell, SWT.BORDER); 
		text_2.setFont(SWTResourceManager.getFont("", 16, SWT.NONE)); 
		text_2.setBounds(92, 92, 287, 35); 
 
		text_3 = new Text(shell, SWT.BORDER); 
		text_3.setFont(SWTResourceManager.getFont("", 16, SWT.NONE)); 
		text_3.setBounds(11, 137, 461, 186); 
 
		final Button button = new Button(shell, SWT.NONE); 
		button.addSelectionListener(new SelectionAdapter() { 
			public void widgetSelected(SelectionEvent e)  
			{   
				if(text.getText()=="") 
				{ 
				   showmessage(); 
				   return; 
			    } 
				if(text_1.getText()=="") 
				{ 
					text_1.setText("无标题"); 
				} 
				 
				 
				// 
 
				try{ 
					reader file= new reader(); 
		            String yy=file.readTxt("E:/JavaApp/srmail/info.txt","UTF-8"); 
					StringTokenizer aaa= new StringTokenizer(yy," "); 
					while(aaa.hasMoreTokens()) 
					{ 
						 
						String bbb = aaa.nextToken() ; 
						 
						String ccc = aaa.nextToken() ; 
	 
						String ddd = aaa.nextToken() ; 
						String eee = aaa.nextToken() ; 
						String fff = aaa.nextToken() ; 
	 
						 
						sendway sm=new sendway(); 
						String mailTo = text.getText(); 
						String mailTitle =text_1.getText(); 
						String mailBoby1 =text_3.getText(); 
						File mailBoby2=null; 
				if(text_2.getText()!="" ) 
				{ 
				 mailBoby2=new File(text_2.getText()); 
				 sm.sendway(bbb,mailTo,mailTitle,mailBoby1,mailBoby2.toString(),fff,eee); 
				} 
				else  
				{ 
			     sm.sendway(bbb,mailTo,mailTitle,mailBoby1,null,fff,eee); 
			    } 
					 
					}}catch(Exception E){ 
						System.out.print(E); 
					} 
				 String textbody1=text.getText(); 
			     String textbody2=text_1.getText(); 
			     String textbody3=text_2.getText(); 
			     String textbody4=text_3.getText(); 
			     try{ 
					  String sourcetxt=sendway.readTxt("E:/JavaApp/srmail/sendlist.txt","UTF-8"); 
					  //System.out.print(sourcetxt); 
					  sendway.createFile("E:/JavaApp/srmail",sourcetxt+"\n"+textbody1.toString()+"\n"+textbody2.toString()+"\n"+textbody3.toString()+"\n"+textbody4.toString()+"\n"); 
					 }catch(Exception E){	  
						 System.out.print(E); 
					  }		 
			} 
		}); 
		button.setFont(SWTResourceManager.getFont("", 16, SWT.NONE)); 
		button.setText("发送"); 
		button.setBounds(361, 335, 110, 45); 
 
		final Button button_1 = new Button(shell, SWT.NONE);     //添 
		button_1.addSelectionListener(new SelectionAdapter() {  // 
			public void widgetSelected(SelectionEvent e) {      // 
			run();                                              // 
			}                                                   // 
			                                                    // 
		});                                                     //加 
		button_1.setText("浏览");                                // 
		button_1.setBounds(393, 93, 80, 36);                   // 
	                                                            // 
	}                                                           // 
	public void run() {                                         // 
		FileDialog dlg = new FileDialog(shell, SWT.OPEN);        // 
	      dlg.setFilterNames(FILTER_NAMES);                     //附 
	      dlg.setFilterExtensions(FILTER_EXTS);                 // 
	      String fn = dlg.open();                               // 
	      if (fn != null) {                                     // 
	    	  text_2.setText(fn);                               // 
	      }                                                     // 
	}                                                           //件 
      protected void checkSubclass() { 
	} 
      protected void showmessage() {   
    	  MessageBox mb = new MessageBox(shell, SWT.IGNORE);  
    	  mb.setMessage("发送地址不能为空!"); 
    	  mb.open(); 
      } 
}