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

📄 mail.jsp

📁 jsp动态网站开发与实例(第3版) 源码
💻 JSP
字号:
	<%@page contentType="text/html"%>
	<%@page pageEncoding="Ms950"%>
	<%@page import ="java.util.*,java.io.*"%>
	
	<%@page import ="javax.mail.*"%>
	<%@page import ="javax.mail.internet.*"%>
	<%@page import ="javax.activation.*"%>
	<html>
	    <head><title>发送邮件界面</title></head>
	    <body>
	      <%       
	        request.setCharacterEncoding("Ms950") ; 
	        Properties theProperties = System.getProperties() ; 
	        theProperties.put("mail.host","127.0.0.1") ; 
	        theProperties.put("mail.transport.protocol","smtp") ; 
	    
	        Session theSession =
	 		 Session.getDefaultInstance(theProperties,null) ; 
	        theSession.setDebug(false) ;     
	        
	        MimeMessage theMessage = new MimeMessage(theSession) ;        
	        theMessage.setFrom(new InternetAddress(
	                request.getParameter("sendname")) ) ;         
	        theMessage.setRecipients(Message.RecipientType.TO,
	                request.getParameter("acceptname")) ; 
	        
	        theMessage.setSubject(request.getParameter("subject")) ;             
	        MimeBodyPart theMimeBodytext = new MimeBodyPart() ;
	        theMimeBodytext.setText(request.getParameter("content")) ; 
	        Multipart theMultipart = new MimeMultipart();
	        theMultipart.addBodyPart(theMimeBodytext) ;  
	    
	        String theFileName =request.getParameter("attachfile"); 
	        if(theFileName.length()> 0){            
	            MimeBodyPart theMimeBodyPart = new MimeBodyPart() ;
	            FileDataSource theFileDataSource= 
	 					new FileDataSource(theFileName) ; 
	            theMimeBodyPart.setDataHandler
	 			(new DataHandler(theFileDataSource)) ; 
	            theMimeBodyPart.setFileName
	 			(theFileDataSource.getName()) ;             
	            theMultipart.addBodyPart(theMimeBodyPart) ;                        
	        }    
	        theMessage.setContent(theMultipart) ; 
	        Transport.send(theMessage) ; 
	        out.println("成功发送邮件") ;  
	              
	    %>
	    </body>
	</html>

⌨️ 快捷键说明

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