首页 新闻 会员 周边 捐助

The import java.mail cannot be resolved

0
悬赏园豆:20 [已解决问题] 解决于 2017-08-05 10:31

就是一个简易用JSP发送邮件的代码,可是我明明导入包了也CLEAR了还是不对!

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import = "java.io.*,java.util.*" %>
<%@ page import = "javax.mail.internet.*,javax.activation.*" %>
<%@ page import = "javax.servlet.http.*,javax.servlet.*" %>
<%@ page import = "java.mail.*"%>
<%
String result;
String to = "11111@sina.com";
String from = "22222@sina.com";
String host = "loaclhost";
Properties prop= new Properties();
prop.put("mail.smtp.host","smtp.jspinsider.com");
Session sendmailSession;
sendmailSession = Session.getInstance(prop,null);
try{
MimeMessage message = new MimeMessage(sendmailSession);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("hello world!");
message.setText("你好,世界");
Transport transport;
transport.sendmailSession.getInstance("smtp");
result = "邮件已发送...";
}catch(MessagingException mex)
{
mex.printStackTrace();
result = "ERROR :unable to send message...";
}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>send email using JSP</title>
</head>
<body>
<p align="center"> <% out.println("result:"+result +"\n"); %></p>
</body>
</html>

耳朵嫁给了真正的谎的主页 耳朵嫁给了真正的谎 | 初学一级 | 园豆:195
提问于:2017-08-04 17:29
< >
分享
最佳答案
0

改成<%@ page import = "javax.mail.*"%>看看

收获园豆:15
湛泸 | 菜鸟二级 |园豆:239 | 2017-08-04 18:04

改过,没用

耳朵嫁给了真正的谎 | 园豆:195 (初学一级) | 2017-08-04 18:05
其他回答(1)
0

参考

https://stackoverflow.com/questions/12795614/the-import-javax-mail-cannot-be-resolved

ycyzharry | 园豆:25683 (高人七级) | 2017-08-04 18:40

他说的方法我试过了,我添加了呀

清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册