CST1642 Advanced
Java II
Lab 3 notes
The SMTP (Simple Mail Transfer Protocol) server set up on kaboom.ridgewater.net. Remember, this is outgoing email only. POP3 (Post Office Protocol) is not set up on this server, so you will not be able to receive mail to this account. Here is the information you need. You will not need all of it, but I'll supply everything. SMTP server: kaboom.ridgewater.net Server requires authentication to send
mail for you. To figure out the command sequence for authentication, I set up Outlook Express first and turned logging on. Then I sent some email. Doing this also verified that the SMTP server actually works before I start coding Java. Here is the actual log data that was captured. The only thing changed in the log was I changed the actually encrypted login and username string so that hackers cannot use this log to break into the server. Outlook Express 6.00.2800.1106 (xpsp1.020828-1920) Here is the actual log data when communicating between my Java application and the SMTP mail server. 220 ridgewater.net Microsoft ESMTP MAIL Service,
Version: 5.0.2195.5329 ready at Mon, 27 Jan 2003 11:27:16 -0600 The username and password to your account has to be encrypted using Base64. Below is the code for doing that. // Base64 Encoding routine private final static char base64Array [] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; private static String base64Encode (String string) { String encodedString = ""; byte bytes [] = string.getBytes (); int i = 0; int pad = 0; while (i < bytes.length) { byte b1 = bytes [i++]; byte b2; byte b3; if (i >= bytes.length) { b2 = 0; b3 = 0; pad = 2; } else { b2 = bytes [i++]; if (i >= bytes.length) { b3 = 0; pad = 1; } else b3 = bytes [i++]; } byte c1 = (byte)(b1 >> 2); byte c2 = (byte)(((b1 & 0x3) << 4) | (b2 >> 4)); byte c3 = (byte)(((b2 & 0xf) << 2) | (b3 >> 6)); byte c4 = (byte)(b3 & 0x3f); encodedString += base64Array [c1]; encodedString += base64Array [c2]; switch (pad) { case 0: encodedString += base64Array [c3]; encodedString += base64Array [c4]; break; case 1: encodedString += base64Array [c3]; encodedString += "="; break; case 2: encodedString += "=="; break; } } return encodedString; } Here is the heart of the program: // Connect to the SMTP server on the standard port of 25 java.net.Socket s = new java.net.Socket("kaboom.ridgewater.net", 25); out = new java.io.PrintWriter(s.getOutputStream()); in = new java.io.BufferedReader(new java.io.InputStreamReader(s.getInputStream())); String hostName = java.net.InetAddress.getLocalHost().getHostName(); receive(); // We are doing authentication, so it is "EHLO" instead of "HELO" send("EHLO " + hostName); receive(); // Login authentication send("AUTH LOGIN"); // Read several lines that the server sends back to us. We don't care what it is, // but we need to accept it. receive(); receive(); receive(); receive(); receive(); receive(); receive(); receive(); receive(); receive(); receive(); receive(); receive(); receive(); receive(); // Send the encoded username (which is last name followed by 1st 3 char of first name). send(base64Encode("benusaall")); //username receive(); // Send the encoded password (which is the student ID) send(base64Encode("00000000")); //password receive(); // You should say who you are to the eventual recipient of the email. // \u0040 is unicode for "@". send("MAIL FROM: I would highly recommend displaying your communications between the Java applet and the server in a window for diagnostics purposes.
|