<%@ page contentType="text/html;charset=GBK" %><%@ page import=" javax.mail.*, javax.mail.internet.*, javax.activation.*,java.util.*" %>
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
</HEAD>
<BODY>
<%
try{
Properties props = new Properties();
Session sendMailSession;
Transport transport; sendMailSession = Session.getInstance(props, null);
sendMailSession.setDebug(true);
props.put("mail.smtp.host", "mail.cwap.com");
//props.put("mail.transport.protocol", "smtp");Message newMessage = new MimeMessage(sendMailSession); newMessage.setFrom(new InternetAddress("[email protected]"));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
newMessage.setSubject("subject");
newMessage.setSentDate(new Date());
newMessage.setText("nothing,just a test"); transport = sendMailSession.getTransport("smtp"); // here throws a exception~
transport.send(newMessage);
transport.close();
%>
<P>Your mail has been sent.</P>
<%
}catch(MessagingException m){
out.println(m.toString());
}
%>
</BODY>
</HTML> 这个由问题,就是在家注释的地方跑出异常:javax.mail.NoSuchProviderException: smtp 关注!
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
</HEAD>
<BODY>
<%
try{
Properties props = new Properties();
Session sendMailSession;
Transport transport; sendMailSession = Session.getInstance(props, null);
sendMailSession.setDebug(true);
props.put("mail.smtp.host", "mail.cwap.com");
//props.put("mail.transport.protocol", "smtp");Message newMessage = new MimeMessage(sendMailSession); newMessage.setFrom(new InternetAddress("[email protected]"));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
newMessage.setSubject("subject");
newMessage.setSentDate(new Date());
newMessage.setText("nothing,just a test"); transport = sendMailSession.getTransport("smtp"); // here throws a exception~
transport.send(newMessage);
transport.close();
%>
<P>Your mail has been sent.</P>
<%
}catch(MessagingException m){
out.println(m.toString());
}
%>
</BODY>
</HTML> 这个由问题,就是在家注释的地方跑出异常:javax.mail.NoSuchProviderException: smtp 关注!
某人的协议就是smtp告诉你个好消息,我的问题搞定了