|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
你希望java的IDE整合。这个是没有必要的,重要的是你理解java有多深以及怎么组织你的代码,即使没有IDE,代码照样能够编译运行的。//此段代码用来举行服务器对用户的认证
publicclassEmail_AutherticatorextendsAuthenticator
{
publicEmail_Autherticator()
{
super();
}
publicPasswordAuthenticationgetPasswordAuthentication()
{
returnnewPasswordAuthentication(username,password);
}
}
//该程序为吸收邮件
voidjButton2_actionPerformed(ActionEvente){
try
{
Propertiesprops=System.getProperties();//猎取体系变量
Authenticatorauth=newEmail_Autherticator();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth","true");
Sessionsession=Session.getDefaultInstance(props,auth);//创建session
Storestore=session.getStore("pop3");
store.connect(host,username,password);
//AfterconnectingtotheStore,youcangetaFolder,whichmustbeopenedbeforeyoucanreadmessagesfromit:
Folderfolder=store.getFolder("INBOX");//毗连到Store后,获得一个文件夹,一样平常默许的是INDEX
folder.open(Folder.READ_WRITE);//READ_ONLY为翻开体例
Messagemessage[]=folder.getMessages();//从文件夹猎取邮件信息
//能够用两种体例往取得邮件信息,getContent()用来取得邮件的主体信息。而WriteTo()能够用来取得邮件的全体信息,包含头部信息
//System.out.println(((MimeMessage)message).getContent());
for(inti=0,n=message.length;i{
Stringout_from_person=((InternetAddress)message[i].getFrom()[0]).getPersonal();
Stringout_from_address=((InternetAddress)message[i].getFrom()[0]).getAddress();
System.out.println("From:"+out_from_person+"");
System.out.println("Address:"+out_from_address+"");
Stringout_subject=message[i].getSubject();
System.out.println("Subject:"+out_subject+"");
//以下代码用来取得邮件的注释信息
PartmessagePart=message[i];
Objectout_content=messagePart.getContent();
if(out_contentinstanceofMultipart)
{
messagePart=((Multipart)out_content).getBodyPart(0);
System.out.println("[MultipartMessage]");
}
Stringout_content_type=messagePart.getContentType();
System.out.println("CONTENT:"+out_content_type);
if(out_content_type.startsWith("text/plain")||out_content_type.startsWith("text/html"))
{
InputStreamipstm=messagePart.getInputStream();
BufferedReaderbufreader=newBufferedReader(newInputStreamReader(ipstm));
StringthisLine=bufreader.readLine();
while(thisLine!=null)
{
System.out.println("thisLine:"+thisLine);
thisLine=bufreader.readLine();
}
}
System.out.println("------------------------------------------------------------");
message[i].setFlag(Flags.Flag.DELETED,true);//最初删除服务器真个邮件
}
//DELETED,ANSWERED,DRAFT,FLAGGED,RECENT,SEEN,USER
folder.close(true);//true的话,完全删除已标志为DELETE的邮件,假如为false的话,就不删除
store.close();//封闭
}
catch(Exceptionej2)
{
System.out.println(ej2);
}
}
voidjButton4_actionPerformed(ActionEvente){
try
{//该程序为复兴邮件
Propertiesprops=System.getProperties();//猎取体系变量
Authenticatorauth=newEmail_Autherticator();//获得?uFFFD衿魅现?
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth","true");
Sessionsession=Session.getDefaultInstance(props,auth);//创建session
Storestore=session.getStore("pop3");
store.connect(host,username,password);
Folderfolder=store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
Messagemessage[]=folder.getMessages();
for(inti=0,n=message.length;i{
//Stringout_from_person=((InternetAddress)message[i].getFrom()[0]).getPersonal();//猎取邮件发信人的签名
Stringout_from_address=((InternetAddress)message[i].getFrom()[0]).getAddress();
System.out.println(out_from_address);
Messageforward=newMimeMessage(session);
forward.setSubject("Fwd:"+message[i].getSubject());
forward.setFrom(newInternetAddress(mail_to));
forward.addRecipient(Message.RecipientType.TO,newInternetAddress(out_from_address));
BodyPartmessageBodyPart=newMimeBodyPart();
messageBodyPart.setText("Hereyougowiththeoriginalmessage:");
Multipartmultipart=newMimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart=newMimeBodyPart();
messageBodyPart.setDataHandler(message[i].getDataHandler());
multipart.addBodyPart(messageBodyPart);
forward.setContent(multipart);
Transport.send(forward);
message[i].setFlag(Flags.Flag.DELETED,true);//DELETED,ANSWERED,DRAFT,FLAGGED,RECENT,SEEN,USER
}
folder.close(true);
store.close();//封闭
}
catch(Exceptionej2)
{
System.out.println(ej2);
}
}
voidjButton5_actionPerformed(ActionEvente){
try
{
Propertiesprops=newProperties();
Authenticatorauth=newEmail_Autherticator();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth","true");
Sessionsession=Session.getDefaultInstance(props,auth);
MimeMessagemessage=newMimeMessage(session);
message.setContent("Hello","text/plain");
message.setSubject(mail_subject);
message.setText(mail_body);
message.setHeader(mail_head_name,mail_head_value);
message.setSentDate(newDate());
message.setFrom(newInternetAddress(mail_from,"sunxiaoming"));//tosignalman
认真的记,感觉很紧张根本就没有时间和能力,来对技术知识点进行思考。这样课下就只能对知识进行简单的理解,其实简单的理解就是记忆课堂上讲的知识点, |
|