|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
C#是盗用了Java的源代码,仿照开发的,原因是Java是开源的啊,盗了也白盗,还有一点,开发C#语言的团队是就是开发Java语言的团队,是微软重金挖过去的啊importjavax.mail.*;
importjavax.mail.internet.*;
importjava.util.*;
importjava.io.*;
/**
*Asimpleemailreceiverclass.
*/
publicclassSimpleReceiver{
/**
*Mainmethodtoreceivemessagesfromthemailserverspecified
*ascommandlinearguments.
*/
publicstaticvoidmain(Stringargs[]){
try{
StringpopServer=args[0];
StringpopUser=args[1];
StringpopPassword=args[2];
receive(popServer,popUser,popPassword);
}catch(Exceptionex){
System.out.println("Usage:javacom.lotontech.mail.SimpleReceiver"+"popServerpopUserpopPassword");
}
System.exit(0);
}
/**
*"receive"methodtofetchmessagesandprocessthem.
*/
publicstaticvoidreceive(StringpopServer,StringpopUser,StringpopPassword){
Storestore=null;
Folderfolder=null;
try{
//--Getholdofthedefaultsession--
Propertiesprops=System.getProperties();
Sessionsession=Session.getDefaultInstance(props,null);
//--GetholdofaPOP3messagestore,andconnecttoit--
store=session.getStore("pop3");
store.connect(popServer,popUser,popPassword);
//--Trytogetholdofthedefaultfolder--
folder=store.getDefaultFolder();
if(folder==null)thrownewException("Nodefaultfolder");
//--...anditsINBOX--
folder=folder.getFolder("INBOX");
if(folder==null)thrownewException("NoPOP3INBOX");
//--Openthefolderforreadonly--
folder.open(Folder.READ_ONLY);
//--Getthemessagewrappersandprocessthem--
Message[]msgs=folder.getMessages();
for(intmsgNum=0;msgNum<msgs.length;msgNum++){
printMessage(msgs[msgNum]);
}
}catch(Exceptionex){
ex.printStackTrace();
}
finally{
//--Closedownnicely--
try{
if(folder!=null)folder.close(false);
if(store!=null)store.close();
}catch(Exceptionex2){
ex2.printStackTrace();
}
}
}
/**
*"printMessage()"methodtoprintamessage.
*/
publicstaticvoidprintMessage(Messagemessage){
try{
//Gettheheaderinformation
Stringfrom=((InternetAddress)message.getFrom()[0]).getPersonal();
if(from==null)from=((InternetAddress)message.getFrom()[0]).getAddress();
System.out.println("FROM:"+from);
Stringsubject=message.getSubject();
System.out.println("SUBJECT:"+subject);
//--Getthemessagepart(i.e.themessageitself)--
PartmessagePart=message;
Objectcontent=messagePart.getContent();
//--oritsfirstbodypartifitisamultipartmessage--
if(contentinstanceofMultipart){
messagePart=((Multipart)content).getBodyPart(0);
System.out.println("[MultipartMessage]");
}
//--Getthecontenttype--
StringcontentType=messagePart.getContentType();
//--Ifthecontentisplaintext,wecanprintit--
System.out.println("CONTENT:"+contentType);
if(contentType.startsWith("text/plain")||
contentType.startsWith("text/html")){
InputStreamis=messagePart.getInputStream();
BufferedReaderreader=newBufferedReader(newInputStreamReader(is));
StringthisLine=reader.readLine();
while(thisLine!=null){
System.out.println(thisLine);
thisLine=reader.readLine();
}
}
System.out.println("-----------------------------");
}catch(Exceptionex){
ex.printStackTrace();
}
}
}
学习JAVA的目的更多的是培养自身的工作能力,我觉得工作能力的一个核心就是:独立思考能力,因为只有独立思考后,才会有自己的见解 |
|