在jsp中,用JAVAMAIL API发送邮件问题,请大家帮忙

bigzhou bigzhou 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我用JBUILDER9,TOMCAT5环境,作了一个HTML文件和JSP文件,JSP文件从HTML文件处得到邮件目的地址和内容等并负责发送。JSP文件代码如下:
<%@ page contentType="text/html;charset=gb2312" %>
<%request.setCharacterEncoding("gb2312");%>
<%@ page import="java.util.*,javax.mail.*,java.net.*,java.net.InetAddress"%>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>发送成功</title>
</head>

<body>
<%
try{

String tto=request.getParameter("to");
String ttitle=request.getParameter("title");
String tcontent=request.getParameter("content");
Properties props=new Properties();
props.put("mail.smtp.host","smtp.163.com");
props.put("mail.smtp.auth","true");
Session s=Session.getInstance(props);
s.setDebug(true);

MimeMessage message=new MimeMessage(s);

//给消息对象设置发件人/收件人/主题/发信时间
InternetAddress from=new InternetAddress("xxxx@163.com");
message.setFrom(from);
InternetAddress to=new InternetAddress(tto);
message.setRecipient(Message.RecipientType.TO,to);
message.setSubject(ttitle);
message.setSentDate(new Date());


//给消息对象设置内容
BodyPart mdp=new MimeBodyPart();//新建一个存放信件内容的BodyPart对象
mdp.setContent(tcontent,"text/html;charset=gb2312");//给BodyPart对象设置内容和格式/编码方式
Multipart mm=new MimeMultipart();//新建一个MimeMultipart对象用来存放BodyPart对
//象(事实上可以存放多个)
mm.addBodyPart(mdp);//将BodyPart加入到MimeMultipart对象中(可以加入多个BodyPart)
message.setContent(mm);//把mm作为消息对象的内容

message.saveChanges();
Transport transport=s.getTransport("smtp");
transport.connect("xxxx@163.com","xxx","xxx");
transport.sendMessage(message,message.getAllRecipients());
transport.close();
%>
<div align="center">
<p><font color="#FF6600">发送成功!</font></p>

<br>
<a href="face.htm">再发一封</a> </p>
</div>
<%
}catch(MessagingException e){
out.println(e.toString());
}
%>
</body>
</html>

编译可以通过,但运行时网页提示错误:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 13 in the jsp file: /mail_jsp/mail_jspprj/sendmail.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\mail_005fjsp\mail_005fjspprj\sendmail_jsp.java:7: package javax.mail does not exist
import javax.mail.*;
^
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\mail_005fjsp\mail_005fjspprj\sendmail_jsp.java:10: package javax.mail.internet does not exist
import javax.mail.internet.*;
^
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\mail_005fjsp\mail_005fjspprj\sendmail_jsp.java:11: package javax.activation does not exist
import javax.activation.*;
^
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\mail_005fjsp\mail_005fjspprj\sendmail_jsp.java:72: cannot resolve symbol
symbol : class Session


..........
我不知道哪里出了问题
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
bigzhou
Java EE 67,535 成员 225,843 内容