<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 劉錚 閱讀(762) 評論(0)  編輯  收藏 所屬分類: JAVA General

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

    導航

    統計

    留言簿(1)

    文章分類(141)

    文章檔案(147)

    搜索

    最新評論

    主站蜘蛛池模板: 久久精品视频亚洲| 亚洲欧洲日产国码一级毛片| 亚洲91av视频| 久久精品国产免费一区| 国产v亚洲v天堂无码网站| 久久免费美女视频| 亚洲性天天干天天摸| 最近2022中文字幕免费视频| 亚洲网红精品大秀在线观看| 日本黄网站动漫视频免费| 亚洲激情视频图片| 日韩激情淫片免费看| 日本视频免费观看| 亚洲精品无码永久中文字幕| 久久香蕉国产线看免费| 亚洲国产理论片在线播放| 永久免费视频v片www| 国产精品免费αv视频| 亚洲A∨无码一区二区三区| 波多野结衣免费在线观看| 亚洲精品久久无码av片俺去也| 免费a级毛片大学生免费观看| 一个人免费观看视频在线中文 | 222www在线观看免费| 亚洲国产成AV人天堂无码| 免费无码又爽又刺激高潮| 一级一看免费完整版毛片| 久久夜色精品国产亚洲AV动态图 | 亚洲精品视频在线免费| 永久免费av无码网站韩国毛片| 狠狠综合亚洲综合亚洲色| 国产亚洲av片在线观看16女人 | 国产在线观看麻豆91精品免费| 亚洲欧美日韩一区二区三区| 亚洲综合久久夜AV | 精品国产免费人成电影在线观看| 亚洲国产成人AV在线播放| 国产亚洲成av片在线观看| 天天摸夜夜摸成人免费视频| 日韩精品无码免费专区午夜| 亚洲日韩久久综合中文字幕|