有这四个包imap.jar,mailapi.jar,pop3.jar,smtp.jar
可import 这个就出错javax.activation.*;请问这个包在那里?
8 个解决方案
#1
1>javax.activation.*; 70分
2>另外,带认证的MAIL是不是登陆油箱的用户名和密码? 30分,请解释一下
2>另外,带认证的MAIL是不是登陆油箱的用户名和密码? 30分,请解释一下
#2
快来呀
#3
download activation.jar from http://java.sun.com/products/javabeans/glasgow/jaf.html; add it to your class path
2. yes
2. yes
#4
一个发送MAIL的BEAN
package homepage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.Hashtable;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.*;
/**
* Title: JavaMail system
* Description:
* Copyright: Copyright (c) 2002
* Company: home
* @author coolwen.com
* @version 1.0
*/
public class SmtpAuthenticator extends javax.mail.Authenticator{
//SMTP身份验证
protected javax.mail.PasswordAuthentication getPasswordAuthentication()
{
return new javax.mail.PasswordAuthentication("coolwen.com","password");
}
}
package homepage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.Hashtable;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.File;
/**
* Title: JavaMail system
* Description:
* Copyright: Copyright (c) 2002
* Company: home
* @author coolwen.com
* @version 1.0
*/
public class SendMail{
private String smtp="smtp.163.com",from="coolwen.com@163.com";
//发送一个邮件
public boolean SendMail(String subject,String body,String to,String filename){
try {
SmtpAuthenticator sa=new SmtpAuthenticator();
Properties props=System.getProperties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.host",smtp);
Session sess=Session.getInstance(props,sa);
sess.setDebug(true);
Message msg = new MimeMessage(sess);
msg.setDataHandler(new DataHandler(body,"text/html; charset=gb2312"));
if(filename.equals("") || filename == null||filename.equals("null"))
{
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to,false));
msg.setSubject(subject);
}else{
msg.setFrom(new InternetAddress(from));
msg.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(body);
MimeBodyPart mbp2 = new MimeBodyPart();
//File file=new File(filename);
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
msg.setContent(mp);
}
msg.setSentDate(new Date());
//msg.setText(body);
Transport.send(msg);
return true;
} catch (Exception e) {
return false;
}
}
}
在JSP中使用
<%@page contentType="text/html; charset=gb2312" language="java"%>
<jsp:useBean id="send" scope="page" class="homepage.SendMail" />
<%
if(send.SendMail("中国","中国","coolwen.com@163.com","D:\\myGUI.java"))
out.println("ok");
else
out.println("no");
%>
原作者:树叶
来 源:网易
package homepage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.Hashtable;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.*;
/**
* Title: JavaMail system
* Description:
* Copyright: Copyright (c) 2002
* Company: home
* @author coolwen.com
* @version 1.0
*/
public class SmtpAuthenticator extends javax.mail.Authenticator{
//SMTP身份验证
protected javax.mail.PasswordAuthentication getPasswordAuthentication()
{
return new javax.mail.PasswordAuthentication("coolwen.com","password");
}
}
package homepage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.Hashtable;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.File;
/**
* Title: JavaMail system
* Description:
* Copyright: Copyright (c) 2002
* Company: home
* @author coolwen.com
* @version 1.0
*/
public class SendMail{
private String smtp="smtp.163.com",from="coolwen.com@163.com";
//发送一个邮件
public boolean SendMail(String subject,String body,String to,String filename){
try {
SmtpAuthenticator sa=new SmtpAuthenticator();
Properties props=System.getProperties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.host",smtp);
Session sess=Session.getInstance(props,sa);
sess.setDebug(true);
Message msg = new MimeMessage(sess);
msg.setDataHandler(new DataHandler(body,"text/html; charset=gb2312"));
if(filename.equals("") || filename == null||filename.equals("null"))
{
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to,false));
msg.setSubject(subject);
}else{
msg.setFrom(new InternetAddress(from));
msg.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(body);
MimeBodyPart mbp2 = new MimeBodyPart();
//File file=new File(filename);
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
msg.setContent(mp);
}
msg.setSentDate(new Date());
//msg.setText(body);
Transport.send(msg);
return true;
} catch (Exception e) {
return false;
}
}
}
在JSP中使用
<%@page contentType="text/html; charset=gb2312" language="java"%>
<jsp:useBean id="send" scope="page" class="homepage.SendMail" />
<%
if(send.SendMail("中国","中国","coolwen.com@163.com","D:\\myGUI.java"))
out.println("ok");
else
out.println("no");
%>
原作者:树叶
来 源:网易
#5
1,tomcat\common\lib\activation.jar(安装tomcat后会有自带)
2,yes
2,yes
#6
我TRY一下,通过了就散分
#7
你要是有j2ee.jar
import它,什么都省了
import它,什么都省了
#8
加入类路径中不就行了吗
#1
1>javax.activation.*; 70分
2>另外,带认证的MAIL是不是登陆油箱的用户名和密码? 30分,请解释一下
2>另外,带认证的MAIL是不是登陆油箱的用户名和密码? 30分,请解释一下
#2
快来呀
#3
download activation.jar from http://java.sun.com/products/javabeans/glasgow/jaf.html; add it to your class path
2. yes
2. yes
#4
一个发送MAIL的BEAN
package homepage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.Hashtable;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.*;
/**
* Title: JavaMail system
* Description:
* Copyright: Copyright (c) 2002
* Company: home
* @author coolwen.com
* @version 1.0
*/
public class SmtpAuthenticator extends javax.mail.Authenticator{
//SMTP身份验证
protected javax.mail.PasswordAuthentication getPasswordAuthentication()
{
return new javax.mail.PasswordAuthentication("coolwen.com","password");
}
}
package homepage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.Hashtable;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.File;
/**
* Title: JavaMail system
* Description:
* Copyright: Copyright (c) 2002
* Company: home
* @author coolwen.com
* @version 1.0
*/
public class SendMail{
private String smtp="smtp.163.com",from="coolwen.com@163.com";
//发送一个邮件
public boolean SendMail(String subject,String body,String to,String filename){
try {
SmtpAuthenticator sa=new SmtpAuthenticator();
Properties props=System.getProperties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.host",smtp);
Session sess=Session.getInstance(props,sa);
sess.setDebug(true);
Message msg = new MimeMessage(sess);
msg.setDataHandler(new DataHandler(body,"text/html; charset=gb2312"));
if(filename.equals("") || filename == null||filename.equals("null"))
{
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to,false));
msg.setSubject(subject);
}else{
msg.setFrom(new InternetAddress(from));
msg.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(body);
MimeBodyPart mbp2 = new MimeBodyPart();
//File file=new File(filename);
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
msg.setContent(mp);
}
msg.setSentDate(new Date());
//msg.setText(body);
Transport.send(msg);
return true;
} catch (Exception e) {
return false;
}
}
}
在JSP中使用
<%@page contentType="text/html; charset=gb2312" language="java"%>
<jsp:useBean id="send" scope="page" class="homepage.SendMail" />
<%
if(send.SendMail("中国","中国","coolwen.com@163.com","D:\\myGUI.java"))
out.println("ok");
else
out.println("no");
%>
原作者:树叶
来 源:网易
package homepage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.Hashtable;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.*;
/**
* Title: JavaMail system
* Description:
* Copyright: Copyright (c) 2002
* Company: home
* @author coolwen.com
* @version 1.0
*/
public class SmtpAuthenticator extends javax.mail.Authenticator{
//SMTP身份验证
protected javax.mail.PasswordAuthentication getPasswordAuthentication()
{
return new javax.mail.PasswordAuthentication("coolwen.com","password");
}
}
package homepage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.Hashtable;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.File;
/**
* Title: JavaMail system
* Description:
* Copyright: Copyright (c) 2002
* Company: home
* @author coolwen.com
* @version 1.0
*/
public class SendMail{
private String smtp="smtp.163.com",from="coolwen.com@163.com";
//发送一个邮件
public boolean SendMail(String subject,String body,String to,String filename){
try {
SmtpAuthenticator sa=new SmtpAuthenticator();
Properties props=System.getProperties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.host",smtp);
Session sess=Session.getInstance(props,sa);
sess.setDebug(true);
Message msg = new MimeMessage(sess);
msg.setDataHandler(new DataHandler(body,"text/html; charset=gb2312"));
if(filename.equals("") || filename == null||filename.equals("null"))
{
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to,false));
msg.setSubject(subject);
}else{
msg.setFrom(new InternetAddress(from));
msg.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(body);
MimeBodyPart mbp2 = new MimeBodyPart();
//File file=new File(filename);
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
msg.setContent(mp);
}
msg.setSentDate(new Date());
//msg.setText(body);
Transport.send(msg);
return true;
} catch (Exception e) {
return false;
}
}
}
在JSP中使用
<%@page contentType="text/html; charset=gb2312" language="java"%>
<jsp:useBean id="send" scope="page" class="homepage.SendMail" />
<%
if(send.SendMail("中国","中国","coolwen.com@163.com","D:\\myGUI.java"))
out.println("ok");
else
out.println("no");
%>
原作者:树叶
来 源:网易
#5
1,tomcat\common\lib\activation.jar(安装tomcat后会有自带)
2,yes
2,yes
#6
我TRY一下,通过了就散分
#7
你要是有j2ee.jar
import它,什么都省了
import它,什么都省了
#8
加入类路径中不就行了吗