javamail1.4 编写发送邮件失败! 在线等!!!
准备工作: tomcat 5.5+dk1.5,工作正常,javamail1.4 , jaf-1_1-fr.zip
writemail.jsp 在ROOT/mail文件夹下
<form method= "post " action= "sendmail.jsp " name= "form1 ">
收件人地址: <input type= "text " name= "to ">
主 题: <input type= "text " name= "title ">
内 容: <textarea name= "content " cols= "70 " rows= "10 "> </textarea>
<input type= "submit " name= "Submit " value= "提交 ">
</form>
---------------------------------
sendmail.jsp
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.*,java.util.*,javax.mail.*,javax.mail.internet.*,javax.activation.* "
errorPage= " " %>
<%
try{
//接收邮件信息
String to_mail=request.getParameter( "to ");
String to_title=request.getParameter( "title ");
to_title=new String(to_title.getBytes( "ISO-8859-1 "));
String to_content=request.getParameter( "content ");
to_content=new String(to_content.getBytes( "ISO-8859-1 "));
//接收邮件信息结束
//--------建立邮件会话--------
Properties props=new Properties();//也可用Properties props = System. getProperties();
props.put( "mail.smtp.host ", "smtp.126.com ");//存储发送邮件服务器的信息
props.put( "mail.smtp.auth ", "true ");//同时通过验证
Session s=Session.getInstance(props);//根据属性新建一个邮件会话
s.setDebug(true);
//----由邮件会话新建一个消息对象----
MimeMessage message=new MimeMessage(s);//由邮件会话新建一个消息对象
//--------设置邮件--------
InternetAddress from=new InternetAddress( "tytymnty@126.com ");
message.setFrom(from);//设置发件人
InternetAddress to=new InternetAddress(to_mail);
message.setRecipient(Message.RecipientType.TO,to);//设置收件人,并设置其接收类型为TO
message.setSubject(to_title);//设置主题
message.setText(to_content);//设置信件内容
message.setSentDate(new Date());//设置发信时间
//--------发送邮件--------
message.saveChanges();//存储邮件信息
Transport transport=s.getTransport( "smtp ");
//--以smtp方式登录邮箱,第一个参数是发送邮件用的邮件服务器SMTP地址,第二个参数为用户名,第三个参数为密码
transport.connect( "smtp.126.com ", "tytymnty ", "ty11111111 ");
//发送邮件,其中第二个参数是所有已设好的收件人地址
transport.sendMessage(message,message.getAllRecipients());
transport.close();
%>
<div align= "center ">
<p> 向 <%=to_mail%> 发送邮件成功! <br>
邮件主题: <%=to_title%> <br>
邮件内容: <%=to_content%> </p>
</div>
<%
}catch(
MessagingException e){
out.println( "发送失败! ");
}
%>
-------------------------------------
localhost.log中的错误信息如下:
严重: Servlet.service() for servlet jsp threw exception
把一个非文本文件读成字符串,有哪些后果?该怎么处理