当前位置: 技术问答>java相关
发送e_mail问题??
来源: 互联网 发布时间:2017-04-27
本文导语: 我的发送e_mail程序: package mail; import java.io.*; import javax.mail.*; import java.util.*; import javax.mail.internet.*; import javax.activation.*; public class Email { public Email{ { super(); } public void sendmail(String to,String subject,String...
我的发送e_mail程序:
package mail;
import java.io.*;
import javax.mail.*;
import java.util.*;
import javax.mail.internet.*;
import javax.activation.*;
public class Email
{
public Email{
{
super();
}
public void sendmail(String to,String subject,String body,String filename)
{
Session session;
MimeMessage message;
String host="smtp.263.net";
String from="cwd308-1@263.net";
Properties props=System.getProperties();
props.put("mail.smtp.host",host);
session=Session.getInstance(props,null);
message=new MimeMessage(session);
try
{
message.setFrom(new InternetAddress(from));
message.addRecipoent(Message.RecipientType.To,new InternetAddress(yo));
message.setSubject(subject);
MimeBodyPart mbp1=new MimeBodyPart();
mbp1,setText(body);
MimeBodyPart mbp2=new MimeBodyPart();
FileDataSource fds=new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(filename);
Multipart mp=new Multipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
message.setContent(mp);
message.setSendDate(new java.util.Date());
Transport transport=session.getTransport("smtp");
transport.connect("smtp.263.net",myID","myPWD");
transport.send(message);
}
catch(MessagingException e){}
}
}
当我运行时出现:
C:resin2.1docWEB-INFclassesmailEmail.java:4: Package javax.mail not
found in import.
import javax.mail.*;
^
C:resin2.1docWEB-INFclassesmailEmail.java:6: Package javax.mail.internet
not found in import.
import javax.mail.internet.*;
^
C:resin2.1docWEB-INFclassesmailEmail.java:7: Package javax.activation
not found in import.
import javax.activation.*;
的错误。
这是为什么??
package mail;
import java.io.*;
import javax.mail.*;
import java.util.*;
import javax.mail.internet.*;
import javax.activation.*;
public class Email
{
public Email{
{
super();
}
public void sendmail(String to,String subject,String body,String filename)
{
Session session;
MimeMessage message;
String host="smtp.263.net";
String from="cwd308-1@263.net";
Properties props=System.getProperties();
props.put("mail.smtp.host",host);
session=Session.getInstance(props,null);
message=new MimeMessage(session);
try
{
message.setFrom(new InternetAddress(from));
message.addRecipoent(Message.RecipientType.To,new InternetAddress(yo));
message.setSubject(subject);
MimeBodyPart mbp1=new MimeBodyPart();
mbp1,setText(body);
MimeBodyPart mbp2=new MimeBodyPart();
FileDataSource fds=new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(filename);
Multipart mp=new Multipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
message.setContent(mp);
message.setSendDate(new java.util.Date());
Transport transport=session.getTransport("smtp");
transport.connect("smtp.263.net",myID","myPWD");
transport.send(message);
}
catch(MessagingException e){}
}
}
当我运行时出现:
C:resin2.1docWEB-INFclassesmailEmail.java:4: Package javax.mail not
found in import.
import javax.mail.*;
^
C:resin2.1docWEB-INFclassesmailEmail.java:6: Package javax.mail.internet
not found in import.
import javax.mail.internet.*;
^
C:resin2.1docWEB-INFclassesmailEmail.java:7: Package javax.activation
not found in import.
import javax.activation.*;
的错误。
这是为什么??
|
主要是缺少activation.jar和mail.jar这两个文件
把它们放到
C:resin2.1docWEB-INFlib目录下看看
你用什么编译的
把它们放到
C:resin2.1docWEB-INFlib目录下看看
你用什么编译的
|
用到的jar文件拷到JDK的jrelibext目录下就可以了。
|
关注,是否能用JSP页面写收发邮件,是否还要架设邮件服务器(我是指收邮件)?