高分求助,为何使用javamail发送邮件时出错?
代码是这样的:
<%@ page contentType= "text/html;charset=gb2312 " %>
<%@ page import= "javax.mail.* " %>
<%@ page import= "javax.mail.internet.* " %>
<%@ page import= "java.util.* " %>
<%@ page import= "javax.activation.* " %>
<html>
<head>
<title> 发送邮件 </title>
</head>
<body>
<%
try{
Properties pro=new Properties();
Session sendmailsession;
Transport transport;
sendmailsession=Session.getInstance(pro,null);
pro.put( "mail.smtp.host ", "smtp.126.com ");
Message m=new MimeMessage(sendmailsession);
m.setFrom(new InternetAddress(request.getParameter( "from ")));
m.setRecipient(Message.RecipientType.TO,new InternetAddress(request.getParameter( "to ")));
m.setSubject(request.getParameter( "subject "));
m.setSentDate(new Date());
m.setText(request.getParameter( "content "));
transport=sendmailsession.getTransport( "smtp ");
transport.send(m);
%>
<p> 邮件已经发送成功 </p>
<%
}catch(Exception ex){
out.println(ex.toString());
}
%>
</body>
</html>
不知道为何会错误
错误信息是:
部署tomcat有关问题