欢迎光临
我们一直在努力

JavaMail操作的总结(5)-JSP教程,邮件相关

建站超值云服务器,限时71元/月

//该程序用来接受带有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中文技术网!

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » JavaMail操作的总结(5)-JSP教程,邮件相关
分享到: 更多 (0)