|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
自己的整个学习思路完全被老师的讲课思路所牵制,这样几节课听下来,恐怕自己的见解都应该是书里的知识点了,根本谈不上自身发现问题,分析问题,和解决问题能力的切实提高。//此段代码用来发送带有html信息的邮件
voidjButton8_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);
//设置邮件注释
Stringhtmltext="<h1>hello</h1>"+"<ahref="http://www.ckuyun.com.cn"target="_blank">clickmeplease!</a>";
message.setContent(htmltext,"text/html");//text/plain设置邮件的格局由于是带有html文档的,以是用text/html格局
message.setSubject(mail_subject);
//message.setText(mail_body);在利用message.setContent()时分,好象不克不及用message.setText()
message.setHeader(mail_head_name,mail_head_value);
message.setSentDate(newDate());
Addressaddress=newInternetAddress(mail_from,"sunxiaoming");
message.setFrom(address);
AddresstoAddress=newInternetAddress(mail_to);
message.addRecipient(Message.RecipientType.TO,toAddress);
Transport.send(message);
System.out.println("sendok!");
}
catch(Exceptionex)
{
System.out.println("faild"+ex);
}
}
//此段代码用来发送带有图片的邮件
voidjButton9_actionPerformed(ActionEvente){
try
{
Stringfile="./20020423/test.gif";
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.setSubject("EmbeddedImage");
Addressaddress=newInternetAddress(mail_from,"sunxiaoming");
message.setFrom(address);
AddresstoAddress=newInternetAddress(mail_to);
message.addRecipient(Message.RecipientType.TO,toAddress);
message.setHeader(mail_head_name,mail_head_value);
message.setSentDate(newDate());
BodyPartmessageBodyPart=newMimeBodyPart();
StringhtmlText="<h1></h1>"+"<imgsrc="cid:memememe">";//到场图片
messageBodyPart.setContent(htmlText,"text/html");
//道理同发送附件一样,将邮件当作有多个部分构成的,先设置每个部分,然后再全体将它们合起来便可。
//Createarelatedmulti-parttocombinetheparts
MimeMultipartmultipart=newMimeMultipart("related");
multipart.addBodyPart(messageBodyPart);
//Createpartfortheimage
messageBodyPart=newMimeBodyPart();
//Fetchtheimageandassociatetopart
DataSourcefds=newFileDataSource(file);
messageBodyPart.setDataHandler(newDataHandler(fds));
messageBodyPart.setHeader("Content-ID","memememe");
//Addparttomulti-part
multipart.addBodyPart(messageBodyPart);
//Associatemulti-partwithmessage
message.setContent(multipart);
Transport.send(message);
System.out.println("sendok!");
}
catch(Exceptionex)
{
System.out.println("faild"+ex);
}
}
//该程序用来承受带有html信息的邮件
voidjButton7_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);
Storestore=session.getStore("pop3");
store.connect(host,username,password);
//AfterconnectingtotheStore,youcangetaFolder,whichmustbeopenedbeforeyoucanreadmessagesfromit:
Folderfolder=store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
Messagemessage[]=folder.getMessages();
for(inti=0,n=message.length;i//for(inti=0,n=1;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);
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"))
{
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);
}
folder.close(true);
store.close();
}
catch(Exceptionej2)
{
System.out.println(ej2);
}
}
在1995年5月23日以“Java”的名称正式发布了。 |
|