就是一个简易用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>
改成<%@ page import = "javax.mail.*"%>看看
改过,没用
参考
https://stackoverflow.com/questions/12795614/the-import-javax-mail-cannot-be-resolved
他说的方法我试过了,我添加了呀