JAVAMAIL操作的总结(5)
类别: ASP教程
//该程序用来接受带有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中进行运行
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中进行运行
- 上一篇: 学会在ASP中使用存储过程
- 下一篇: 分栏显示记录集的表格演示,并实现了分页
-= 资 源 教 程 =-
文 章 搜 索