代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Login.jsp' starting page</title>
</head>
<body>
<form action="sendmail.jsp" method=post>
<table>
<tr><td>收件人:<input type=text name=to></td></tr>
<tr><td>发件人:<input type=text name=from></td></tr>
<tr><td>主题:<input type=text name=subject></td></tr>
<tr><td>内容;<textarea name=content></textarea>
<tr><td><input type=submit value=send ><input type=reset value=aaa></td></tr>
</table>
</form>
</body>
</html>
处理页面:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="javax.mail.*, javax.mail.internet.*, javax.activation.*, java.util.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'sendmail.jsp' starting page</title>
</head>
<% request.setCharacterEncoding("gb2312"); %>
<body>
<%
try{
Properties props=System.getProperties();
Session sendmailSession;
Transport transport;
sendmailSession=Session.getDefaultInstance(props,null);
props.put("mail.smtp.host","smtp.sina.com.cn");
//props.put("mail.smtp.prot","25");
Message newMessage=new MimeMessage(sendmailSession);
newMessage.setFrom(new InternetAddress(request.getParameter("from")));
newMessage.addRecipient(Message.RecipientType.TO,new InternetAddress(request.getParameter("to")));
newMessage.setSubject(request.getParameter("subject"));
newMessage.setSentDate(new Date());
newMessage.setText(request.getParameter("content"));
transport =sendmailSession.getTransport("smtp");
transport.send(newMessage);
%>
<p>你的邮件已发送,请返回。</p>
<%
}
catch(MessagingException e){
out.print("错误原因是:"+e);
}
%>
</body>
</html>
错误原因是:javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.SendFailedException: Invalid Addresses; nested exception is: class javax.mail.SendFailedException: 554
是不是我没装SMTP服务器的问题啊?要装这个服务器吗?哪位能帮我改改吗?