//该程序用来接受带有html信息的邮件
void jbutton7_actionperformed(actionevent e) {
try
{
properties props = system.getproperties();
authenticator auth = new email_autherticator();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth","true");
session session = session.getdefaultinstance(props,auth);
store store = session.getstore("pop3");
store.connect(host,username,password);
//after connecting to the store,you can get a folder,which must be opened before you can read messages from it:
folder folder = store.getfolder("inbox");
folder.open(folder.read_write);
message message[] = folder.getmessages();
for (int i=0,n=message.length;i // for (int i=0,n=1;i {
string out_from_person = ((internetaddress)message[i].getfrom()[0]).getpersonal();
string out_from_address = ((internetaddress)message[i].getfrom()[0]).getaddress();
system.out.println("from:"+out_from_person+" ");
system.out.println("address:"+out_from_address+" ");
string out_subject = message[i].getsubject();
system.out.println("subject:"+out_subject+" ");
//获取邮件的信息,并且对其每一部分进行操作
part messagepart = message[i];
object out_content = messagepart.getcontent();
if (out_content instanceof multipart)
{
messagepart = ((multipart)out_content).getbodypart(0);
system.out.println("[ multipart message ]");
}
string out_content_type = messagepart.getcontenttype();
system.out.println("content:"+out_content_type);
jeditorpane1.settext("");//将其显示在jeditorpanel上
jeditorpane1.setcontenttype("text/html");
jeditorpane1.settext((string)out_content);
jeditorpane1.seteditable(false);
/*
if (out_content_type.startswith("text/plain") | | out_content_type.startswith("text/html"))
{
inputstream ipstm = messagepart.getinputstream();
bufferedreader bufreader = new bufferedreader(new inputstreamreader(ipstm));
string thisline = bufreader.readline();
while (thisline != null)
{
system.out.println("thisline: "+thisline);
thisline = bufreader.readline();
}
}
*/
system.out.println("————————————————————");
message[i].setflag(flags.flag.deleted,true);
}
folder.close(true);
store.close();
}
catch(exception ej2)
{
system.out.println(ej2);
}
}
对于上述代码均经过运行通过,
如果不行,可在jbuilder中进行运行,
再次感谢java中文技术网!