?? jfmreplymail.java
字號:
/* * Created on 2004.08.25 * JFreeMail - Java mail component * Copyright (C) 2004 Dalibor Krleza * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.jfreemail.demo;import org.jfreemail.pop3.*;import org.jfreemail.core.*;import org.jfreemail.smtp.*;/** * This demo shows how to reply received E-mail. */public class JfmReplyMail { public static void main(String[] args) { try { /* * We are making pop object. Immediate authentication. If not * thrown exception, object is ready for use. */ JfmPOP3 pop=new JfmPOP3("pop.server.domain",0, JfmConsts.POP3_APOP,"dalibor","secret111"); /* * Download all headers. */ JfmEmailHeader[] email_headers=pop.getMailboxHeaders(); /* * Here goes E-mail choosing. Client choses wich mail to download. * We are dowloading E-mail for first downloaded E-mail header * with index 0. E-mail leaves on POP3 server. We don't want to * delete readed E-mail. */ JfmEmail email=pop.getEmail(email_headers[0],false); /* * Close connection to POP3 server. */ pop.close(); /* * Making reply email. This is a same object with modified sender, * receiver, subject and message. Reply removes all binary parts * from E-mail. */ email.ReplyEmail(); /* * Let's find text message part. We must add our own message. */ JfmEmailTextPart part=null; for(int i=0;i<email.getEmailPartCount();i++) { if (email.getEmailPart(i) instanceof JfmEmailTextPart) { part=(JfmEmailTextPart)email.getEmailPart(i); } } /* * If there is text message, we will add out own at the beginning od * original message. Reply method has already marked older * parts of text message. */ if (part!=null) { String[] reply_message=new String[]{ "Hi Marty\r\n", "\r\n", "I'm appreciating you quick answer. Unfortunately, we are not\r\n", "in position to forfill your demands!\r\n", "\r\n", "Sincerely yours, Dalibor!\r\n"}; String[] out_lines=new String[part.getContent().length+reply_message.length]; for(int i=0;i<reply_message.length;i++) out_lines[i]=reply_message[i]; for(int i=0;i<part.getContent().length;i++) out_lines[i+reply_message.length]=part.getContent()[i]; part.setContent(out_lines); } /* * Creating SMTP object. Immediate authetication. */ JfmSMTP smtp=new JfmSMTP("mail.server.domain",0, JfmConsts.SMTP_LOGIN,"dalibor","secret111"); /* * Send out modified E-mail. */ smtp.sendMail(email); smtp.close(); } catch(Exception exc) { System.out.println(exc.getMessage()); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -