{"id":26589,"date":"2021-04-29T23:10:07","date_gmt":"2021-04-30T03:10:07","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/addressverifier-java-connects-to-an-smtp-server-and-issues-a-expn-request-to-display-details-about-a-mailbox-on-the-server-uses-the-following-classes-programming-code-examples-java-j2ee-j2me-net\/"},"modified":"2021-04-29T23:10:07","modified_gmt":"2021-04-30T03:10:07","slug":"addressverifier-java-connects-to-an-smtp-server-and-issues-a-expn-request-to-display-details-about-a-mailbox-on-the-server-uses-the-following-classes-programming-code-examples-java-j2ee-j2me-net","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=26589","title":{"rendered":"AddressVerifier.java  Connects to an SMTP server and issues a expn request to display details about a mailbox on the server. Uses the following classes: #Programming Code Examples #Java\/J2EE\/J2ME #Network Programming"},"content":{"rendered":"<pre>\n\nAddressVerifier.java  Connects to an SMTP server and issues a expn request to display details about a mailbox on the server. Uses the following classes: \n\nimport java.net.*;\nimport java.io.*;\n\n\/** Given an e-mail address of the form user@host,\n *  connect to port 25 of the host and issue an\n *  'expn' request for the user. Print the results.\n *\n *  Taken from Core Web Programming from\n *  Prentice Hall and Sun Microsystems Press,\n *  .\n *  &copy; 2001 Marty Hall and Larry Brown;\n *  may be freely used or adapted.\n *\/\n\npublic class AddressVerifier extends NetworkClient {\n  private String username;\n\n  public static void main(String[] args) {\n    if (args.length != 1) {\n      usage();\n   }\n    MailAddress address = new MailAddress(args[0]);\n    AddressVerifier verifier\n      = new AddressVerifier(address.getUsername(),\n                            address.getHostname(), 25);\n    verifier.connect();\n  }\n\n  public AddressVerifier(String username, String hostname,\n                         int port) {\n    super(hostname, port);\n    this.username = username;\n  }\n\n  \/** NetworkClient, the parent class, automatically establishes\n   *  the connection and then passes the Socket to\n   *  handleConnection. This method does all the real work\n   *  of talking to the mail server.\n   *\/\n\n  \/\/ You can't use readLine, because it blocks. Blocking I\/O\n  \/\/ by readLine is only appropriate when you know how many\n  \/\/ lines to read. Note that mail servers send a varying\n  \/\/ number of lines when you first connect or send no line\n  \/\/ closing the connection (as HTTP servers do), yielding\n  \/\/ null for readLine. Also, we'll assume that 1000 bytes\n  \/\/ is more than enough to handle any server welcome\n  \/\/ message and the actual EXPN response.\n\n  protected void handleConnection(Socket client) {\n    try {\n      PrintWriter out = SocketUtil.getWriter(client);\n      InputStream in = client.getInputStream();\n      byte[] response = new byte[1000];\n      \/\/ Clear out mail server's welcome message.\n      in.read(response);\n      out.println(&quot;EXPN &quot; + username);\n      \/\/ Read the response to the EXPN command.\n      int numBytes = in.read(response);\n      \/\/ The 0 means to use normal ASCII encoding.\n      System.out.write(response, 0, numBytes);\n      out.println(&quot;QUIT&quot;);\n      client.close();\n    } catch(IOException ioe) {\n      System.out.println(&quot;Couldn't make connection: &quot; + ioe);\n    }\n  }\n\n  \/** If the wrong arguments, thn warn user. *\/\n\n  public static void usage() {\n    System.out.println (&quot;You must supply an email address &quot; +\n       &quot;of the form 'username@hostname'.&quot;);\n    System.exit(-1);\n  }\n}\n\n\nMailAddress.java  Separates the user and host components of an email address. \n\nimport java.util.*;\n\n\/** Takes a string of the form &quot;user@host&quot; and\n *  separates it into the &quot;user&quot; and &quot;host&quot; parts.\n *\n *  Taken from Core Web Programming from\n *  Prentice Hall and Sun Microsystems Press,\n *  .\n *  &copy; 2001 Marty Hall and Larry Brown;\n *  may be freely used or adapted.\n *\/\n\npublic class MailAddress {\n  private String username, hostname;\n\n  public MailAddress(String emailAddress) {\n    StringTokenizer tokenizer\n      = new StringTokenizer(emailAddress, &quot;@&quot;);\n    this.username = getArg(tokenizer);\n    this.hostname = getArg(tokenizer);\n  }\n\n  private static String getArg(StringTokenizer tok) {\n    try { return(tok.nextToken()); }\n    catch (NoSuchElementException nsee) {\n      System.out.println(&quot;Illegal email address&quot;);\n      System.exit(-1);\n      return(null);\n    }\n  }\n\n  public String getUsername() {\n    return(username);\n  }\n\n  public String getHostname() {\n    return(hostname);\n  }\n}\n\n\nNetworkClient.java  Starting point for a network client to communicate with a remote computer.\n\nimport java.net.*;\nimport java.io.*;\n\n\/** A starting point for network clients. You'll need to\n *  override handleConnection, but in many cases connect can\n *  remain unchanged. It uses SocketUtil to simplify the\n *  creation of the PrintWriter and BufferedReader.\n *\n *  Taken from Core Web Programming from\n *  Prentice Hall and Sun Microsystems Press,\n *  .\n *  &copy; 2001 Marty Hall and Larry Brown;\n *  may be freely used or adapted.\n *\/\n\npublic class NetworkClient {\n  protected String host;\n  protected int port;\n\n  \/** Register host and port. The connection won't\n   *  actually be established until you call\n   *  connect.\n   *\/\n\n  public NetworkClient(String host, int port) {\n    this.host = host;\n    this.port = port;\n  }\n\n  \/** Establishes the connection, then passes the socket\n   *  to handleConnection.\n   *\/\n\n  public void connect() {\n    try {\n      Socket client = new Socket(host, port);\n      handleConnection(client);\n    } catch(UnknownHostException uhe) {\n      System.out.println(&quot;Unknown host: &quot; + host);\n      uhe.printStackTrace();\n    } catch(IOException ioe) {\n      System.out.println(&quot;IOException: &quot; + ioe);\n      ioe.printStackTrace();\n    }\n  }\n\n  \/** This is the method you will override when\n   *  making a network client for your task.\n   *  The default version sends a single line\n   *  (&quot;Generic Network Client&quot;) to the server,\n   *  reads one line of response, prints it, then exits.\n   *\/\n\n  protected void handleConnection(Socket client)\n    throws IOException {\n    PrintWriter out = SocketUtil.getWriter(client);\n    BufferedReader in = SocketUtil.getReader(client);\n    out.println(&quot;Generic Network Client&quot;);\n    System.out.println\n      (&quot;Generic Network Client:n&quot; +\n       &quot;Made connection to &quot; + host +\n       &quot; and got '&quot; + in.readLine() + &quot;' in response&quot;);\n    client.close();\n  }\n\n  \/** The hostname of the server we're contacting. *\/\n\n  public String getHost() {\n    return(host);\n  }\n\n  \/** The port connection will be made on. *\/\n\n  public int getPort() {\n    return(port);\n  }\n}\n\n\nSocketUtil.java  Provides utilities for wrapping a BufferedReader  and PrintWriter around the Socket's input and output streams, respectively. \n\nimport java.net.*;\nimport java.io.*;\n\n\/** A shorthand way to create BufferedReaders and\n *  PrintWriters associated with a Socket.\n *\n *  Taken from Core Web Programming from\n *  Prentice Hall and Sun Microsystems Press,\n *  .\n *  &copy; 2001 Marty Hall and Larry Brown;\n *  may be freely used or adapted.\n *\/\n\npublic class SocketUtil {\n  \/** Make a BufferedReader to get incoming data. *\/\n\n  public static BufferedReader getReader(Socket s)\n      throws IOException {\n    return(new BufferedReader(\n       new InputStreamReader(s.getInputStream())));\n  }\n\n  \/** Make a PrintWriter to send outgoing data.\n   *  This PrintWriter will automatically flush stream\n   *  when println is called.\n   *\/\n\n  public static PrintWriter getWriter(Socket s)\n      throws IOException {\n    \/\/ Second argument of true means autoflush.\n    return(new PrintWriter(s.getOutputStream(), true));\n  }\n}\n\n\n\n<\/pre>\n<p>Note: Brought from our old site: http:\/\/www.salearningschool.com\/example_codes\/ on Jan 2nd, 2017 From: http:\/\/sitestree.com\/?p=10229<br \/> Categories:Programming Code Examples, Java\/J2EE\/J2ME, Network Programming<br \/>Tags:Java\/J2EE\/J2MENetwork Programming<br \/> Post Data:2017-01-02 16:04:28<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>AddressVerifier.java Connects to an SMTP server and issues a expn request to display details about a mailbox on the server. Uses the following classes: import java.net.*; import java.io.*; \/** Given an e-mail address of the form user@host, * connect to port 25 of the host and issue an * &#8216;expn&#8217; request for the user. Print &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=26589\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-26589","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10189,"url":"http:\/\/bangla.sitestree.com\/?p=10189","url_meta":{"origin":26589,"position":0},"title":"AddressVerifier.java Connects to an SMTP server and issues a expn request to display details about a mailbox on the server. Uses the following classes","author":"","date":"August 24, 2015","format":false,"excerpt":"import java.net.*; import java.io.*; \/** Given an e-mail address of the form user@host, \u00a0*\u00a0 connect to port 25 of the host and issue an \u00a0*\u00a0 'expn' request for the user. Print the results. \u00a0* \u00a0*\u00a0 Taken from Core Web Programming from \u00a0*\u00a0 Prentice Hall and Sun Microsystems Press, \u00a0*\u00a0 .\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26489,"url":"http:\/\/bangla.sitestree.com\/?p=26489","url_meta":{"origin":26589,"position":1},"title":"UriRetriever.java  Accepts a host, port, and file from the command line and retrieves the implied URL from the HTTP server by issuing a GET request. Uses the following classes: #Programming Code Examples #NULL #Network Programming","author":"Author-Check- Article-or-Video","date":"April 26, 2021","format":false,"excerpt":"UriRetriever.java Accepts a host, port, and file from the command line and retrieves the implied URL from the HTTP server by issuing a GET request. Uses the following classes: import java.net.*; import java.io.*; \/** Retrieve a URL given the host, port, and file as three * separate command-line arguments. A\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10202,"url":"http:\/\/bangla.sitestree.com\/?p=10202","url_meta":{"origin":26589,"position":2},"title":"EchoServer.java A simple HTTP server that creates a Web page showing all data sent from the client (browser), including all HTTP request headers sent form the client. Uses the following classes","author":"","date":"August 25, 2015","format":false,"excerpt":"EchoServer.java\u00a0 A simple HTTP server that creates a Web page showing all data sent from the client (browser), including all HTTP request headers sent form the client. Uses the following classes: \u00a0 import java.net.*; import java.io.*; import java.util.StringTokenizer; \/** A simple HTTP server that generates a Web page showing all\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10206,"url":"http:\/\/bangla.sitestree.com\/?p=10206","url_meta":{"origin":26589,"position":3},"title":"RMI Example &#8211; Message, illustrates retrieving a message from an object located on a remote server. Requires the following classes","author":"","date":"August 25, 2015","format":false,"excerpt":"Rem.java\u00a0 Establishes which methods the client can access in the remote object. import java.rmi.*; \/** The RMI client will use this interface directly. The RMI \u00a0*\u00a0 server will make a real remote object that implements this, \u00a0*\u00a0 then register an instance of it with some URL. \u00a0* \u00a0*\u00a0 Taken from\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26745,"url":"http:\/\/bangla.sitestree.com\/?p=26745","url_meta":{"origin":26589,"position":4},"title":"RMI Example &#8211; Message, illustrates retrieving a message from an object located on a remote server. Requires the following classes: #Programming Code Examples #Java\/J2EE\/J2ME #Network Programming","author":"Author-Check- Article-or-Video","date":"April 30, 2021","format":false,"excerpt":"RMI Example - Message, illustrates retrieving a message from an object located on a remote server. Requires the following classes: Rem.java Establishes which methods the client can access in the remote object. import java.rmi.*; \/** The RMI client will use this interface directly. The RMI * server will make a\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26741,"url":"http:\/\/bangla.sitestree.com\/?p=26741","url_meta":{"origin":26589,"position":5},"title":"EchoServer.java  A simple HTTP server that creates a Web page showing all data sent from the client (browser), including all HTTP request headers sent form the client. Uses the following classes: #Programming Code Examples #Java\/J2EE\/J2ME #Network Programming","author":"Author-Check- Article-or-Video","date":"April 30, 2021","format":false,"excerpt":"EchoServer.java A simple HTTP server that creates a Web page showing all data sent from the client (browser), including all HTTP request headers sent form the client. Uses the following classes: import java.net.*; import java.io.*; import java.util.StringTokenizer; \/** A simple HTTP server that generates a Web page showing all *\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26589"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26589\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26589"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}