当前位置: 技术问答>HTML标签参考手册
iis7站长之家
javamail 配置总不成功,帮忙,在线给分,言必有信!!
来源: 互联网 发布时间:2015-08-09
本文导语: JDK1.3+JAVAMAIL1.13+JavaBeans Activation Framework 1.02 activation.jar,mail.jar放置于jdk1.3jrelibetc目录下: 编译如下程序通过,运行时报错: 编译如下程序: import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; pub...
JDK1.3+JAVAMAIL1.13+JavaBeans Activation Framework 1.02
activation.jar,mail.jar放置于jdk1.3jrelibetc目录下:
编译如下程序通过,运行时报错:
编译如下程序:
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class MailExample
{
public static void main(String args[])
throws Exception
{
String host=args[0];
String from=args[1];
String to=args[2];
//Get system properties
Properties props=System.getProperties();
//Setup mail server
props.put("mail.smtp.host",host);
//Get Session
Session session =Session.getInstance(props,null);
//Define message
MimeMessage message=new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");
//send message
Transport.send(message);
}
}
运行时报错:
Exception in thread "main" java.lang.NoClassDeFoundError:javax/mail/Address
请问何故?在线等候,立即给分!!
activation.jar,mail.jar放置于jdk1.3jrelibetc目录下:
编译如下程序通过,运行时报错:
编译如下程序:
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class MailExample
{
public static void main(String args[])
throws Exception
{
String host=args[0];
String from=args[1];
String to=args[2];
//Get system properties
Properties props=System.getProperties();
//Setup mail server
props.put("mail.smtp.host",host);
//Get Session
Session session =Session.getInstance(props,null);
//Define message
MimeMessage message=new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");
//send message
Transport.send(message);
}
}
运行时报错:
Exception in thread "main" java.lang.NoClassDeFoundError:javax/mail/Address
请问何故?在线等候,立即给分!!
|
sendmail.jsp文件
<%@ page import=" Javax.mail.*, Javax.mail.internet.*, Javax.activation.*,Java.util.*"%>
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
</head>
<body>
<%
try{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
sendMailSession = Session.getInstance(props, null);
props.put("mail.smtp.host", "smtp.jspinsider.com");
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(request.getParameter("from")));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress ( request.getParameter ("to")));
newMessage.setSubject(request.getParameter("subject"));
newMessage.setSentDate(new Date());
newMessage.setText(request.getParameter("text"));
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
%>
<P>Your mail has been sent.</P>
<%
}catch(MessagingException m)
{
out.println(m.toString());
}
%>
</body>
</html>
<%@ page import=" Javax.mail.*, Javax.mail.internet.*, Javax.activation.*,Java.util.*"%>
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
</head>
<body>
<%
try{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
sendMailSession = Session.getInstance(props, null);
props.put("mail.smtp.host", "smtp.jspinsider.com");
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(request.getParameter("from")));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress ( request.getParameter ("to")));
newMessage.setSubject(request.getParameter("subject"));
newMessage.setSentDate(new Date());
newMessage.setText(request.getParameter("text"));
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
%>
<P>Your mail has been sent.</P>
<%
}catch(MessagingException m)
{
out.println(m.toString());
}
%>
</body>
</html>
|
你的程序没有问题,我将你的程序放在了
JB底下运行没有问题
请检查你的mail类和classpa。
JB底下运行没有问题
请检查你的mail类和classpa。
|
你在CLASSSPATH加上mail.jar的存放路径
|
试试这个:
set classpath=%classpath%;c:jdk1.3jrelibetcmail.jar;c:jdk1.3jrelibetcactivation.jar(把盘符改掉)。
set classpath=%classpath%;c:jdk1.3jrelibetcmail.jar;c:jdk1.3jrelibetcactivation.jar(把盘符改掉)。
|
不可能阿,我不运行这句话,和你同样的问题,运行之后,他说找不到MailExample,我把当前路径加入classpath,就一切OK了,你检查一下你原来的classpath.或者建议你这样做,在你的mailexample.class的目录下执行set classpath=c:jdk1.3jrelibetcmail.jar;c:jdk1.3jrelibetcactivation.jar;.
注意你的jdk1.3是不是在c盘根目录下。
注意你的jdk1.3是不是在c盘根目录下。
|
是不是你的参数不对无法得到address呢?
|
你在args参数中的host是什么?
|
http://www.csdn.net/Expert/TopicView1.asp?id=679555