<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    利用jakarta Commons組件收發郵件

    發郵件:

    Telnet to port 25 of a SMTP server, and you will see the server respond with a numeric code (220). SMTPReply.isPositiveCompletion( ) returns true if the response code of the previously executed command is between 200 and 299; the value of the initial response code, 220, is equal to the public static variable SMTPReply.SERVICE_READY. The following example uses getReplyCode( ) and SMTPReply.isPositiveCompletion() to test the connection to the SMTP server:

    import org.apache.commons.net.smtp.SMTP;
    import org.apache.commons.net.smtp.SMTPClient;
    import org.apache.commons.net.smtp.SMTPReply;
    SMTPClient client = new SMTPClient( );
    client.connect("www.discursive.com");
    int response = client.getReplyCode( );
    if( SMTPReply.isPositiveCompletion( response ) ) {
    // Set the sender and the recipients
    client.setSender( "tobrien@discursive.com" );
    client.addRecipient( "president@whitehouse.gov" );
    client.addRecipient( "vicepresident@whitehouse.gov" );
    // Supply the message via a Writer
    Writer message = client.sendMessageData( );
    message.write( "Spend more money on energy research.  Thanks." );
    message.close( );
    // Send the message and print a confirmation
    boolean success = client.completePendingCommand( );
    if( success ) {
    System.out.println( "Message sent" );
    }
    } else {
    System.out.println( "Error communicating with SMTP server" );
    }
    client.disconnect( );

    Instead of sendSimpleMessage( ), the previous example sets a sender address and two recipient addresses using setSender( ) and addRecipient(). The message body is then written to a Writer returned by sendMessageData(). When the Writer is closed, the message is sent by calling completePendingCommand(). completePendingCommand( ) returns true if the message has been queued for delivery.

    收郵件:

    Use Commons Net POP3Client to check a POP3 mailbox for incoming mail. The following example connects to the POP3 server www.discursive.com, logs in as tobrien@discursive.com, and prints each message in the mailbox:

    import org.apache.commons.io.CopyUtils;
    import org.apache.commons.io.IOUtils;
    import org.apache.commons.net.pop3.POP3Client;
    import org.apache.commons.net.pop3.POP3MessageInfo;
    POP3Client client = new POP3Client( );
    client.connect("www.discursive.com");
    client.login("tobrien@discursive.com", "secretpassword");
    POP3MessageInfo[] messages = client.listMessages( );
    for (int i = 0; i < messages.length; i++) {
    int messageNum = messages[i].number;
    System.out.println( "************* Message number: " + messageNum );
    Reader reader = client.retrieveMessage( messageNum );
    System.out.println( "Message:\n" + IOUtils.toString( reader ) );
    IOUtils.closeQuietly( reader );
    }
    client.logout( );
    client.disconnect( );

    posted on 2007-11-23 10:13 劉錚 閱讀(761) 評論(0)  編輯  收藏 所屬分類: JAVA General

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    留言簿(1)

    文章分類(141)

    文章檔案(147)

    搜索

    最新評論

    主站蜘蛛池模板: 中文字幕在线观看亚洲| 国产日韩亚洲大尺度高清| 亚洲伊人久久大香线蕉苏妲己| 国产黄在线观看免费观看不卡| 免费国产真实迷j在线观看| 亚洲欧美日韩自偷自拍| 免费高清在线影片一区| 亚洲人av高清无码| 国产免费观看a大片的网站| 亚洲AV永久无码天堂影院| 免费无码一区二区三区蜜桃大| 亚洲精品无码专区在线| 永久免费看mv网站入口| 污网站在线观看免费| 亚洲成a人片在线观看日本麻豆 | 亚洲综合无码无在线观看| 青青青免费国产在线视频小草| 中文字幕亚洲男人的天堂网络| 无码视频免费一区二三区| 国产精品无码亚洲一区二区三区| 国产极品美女高潮抽搐免费网站| 特级毛片A级毛片免费播放| 亚洲一级特黄大片无码毛片| 人妻免费一区二区三区最新| 亚洲视频在线播放| 女人被弄到高潮的免费视频| 免费在线观看亚洲| 亚洲av中文无码乱人伦在线咪咕| 国产成人精品免费视频网页大全| 亚洲人成电影网站色www| 亚洲乱码国产一区网址| 久久久久国产免费| 亚洲精品GV天堂无码男同| 亚洲国产成人久久一区久久| 日韩免费在线视频| 亚洲熟妇无码av另类vr影视 | 国产精品视频永久免费播放| 免费无码国产在线观国内自拍中文字幕 | 国产精品免费久久久久电影网| 亚洲国产精品自在在线观看| 午夜寂寞在线一级观看免费|