jsp_smtp验证发邮参考.txt

来自「jsp开发的15个案例的源码」· 文本 代码 · 共 56 行

TXT
56
字号
smtp验证发邮参考 
发布日期:2003-11-27 作者:hypcloud 阅读人次:11362 
  
CODE:
--------------------------------------------------------------------------------

  <%@ page import="javax.mail.*"%>  
<%@ page import="javax.mail.internet.*"%>  
<%@ page import="javax.activation.*"%>   
<%@ page import="java.util.*"%>   
<jsp:useBean id="asciitoch" scope="page" class="email.AsctoCh" /> 
  <html>  
 <head> 
<TITLE>JSP meets JavaMail, what a sweet combo.
</TITLE> 
  </HEAD>   
 <BODY>     
<%!       public class PopupAuthenticator extends Authenticator {          
public PasswordAuthentication getPasswordAuthentication() {             
 String username, password;              
 username = "12345";               
password = "12345";             
return new PasswordAuthentication(username, password);
}            
}           
%>                     
<%            
try{            
Properties props = new Properties();            
Session sendMailSession; 
Store store;             
Transport transport;             
props.put("mail.smtp.host","smtp.21cn.com");             
props.put("mail.smtp.auth","true");             
Authenticator auth = new PopupAuthenticator();             
sendMailSession = Session.getInstance(props,auth);             
sendMailSession.setDebug(true);             
Message newMessage = new MimeMessage(sendMailSession);             
newMessage.setFrom(new InternetAddress("12345@21cn.com"));            
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("12345@hotmail.com")); newMessage.setSubject("subject");             
newMessage.setSentDate(new Date());            
String body = asciitoch.AsciiToChineseString("hello are you?你好吗?"); //上面这个是处理中文字符.            
newMessage.setText(body);             
transport = sendMailSession.getTransport("smtp");              
transport.send(newMessage);               
%>               
<P>Your mail has been sent.</P>                
<%                 
} catch(MessagingException m) {                 
out.println(m.toString());                 
}                
%>            
</BODY>       
</HTML>
 

⌨️ 快捷键说明

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