// fmail - the Java sendmail-connector utility // Copyright 1999 Ng Hsien-Ern, Nathanael // Warning: this program is capable of being used to falsify e-mails, // which is illegal in many countries. // I am not responsible for whatever you do with it. // fmail requires JDK1.1.x to compile. May work, but is untested, under // JDK1.2. The JDK is available from http://java.sun.com. // Send comments, bouquets, brickbats, &c. to nghsiene@comp.nus.edu.sg . // Send angry flames to billgates@microsoft.com . import java.io.*; import java.util.*; import java.net.*; import java.awt.*; public class fmail { public static String addy, port, username, pwd; static InputStream is; static OutputStream os; static Socket sockit; public static void disconnect(){ try { sockit.close(); }catch(Exception e){} } public static void main(String args[]){ System.out.println("fmail 1.0 ready"); System.out.println ("Enter IP address or DNS:"); DataInputStream dis = new DataInputStream (System.in); try { addy = dis.readLine(); try { InetAddress hostaddy = InetAddress.getByName(addy); System.out.println("Host: "+hostaddy.toString()); try { sockit = new Socket (hostaddy,25); is = sockit.getInputStream(); os = sockit.getOutputStream(); char[] inchar = new char[10]; byte[] inbyte = new byte[10]; char bkupchar; int a = 257; boolean b1=true; String str1; StringTokenizer st1; str1 = ""; while (is.available() <= 0){} while (is.available() > 0) { if (is.available() > 9) { is.read(inbyte); for (int l2=0;l2<10;l2++) { inchar[l2] = (char)inbyte[l2]; str1 = str1 + String.valueOf(inchar[l2]); } //this is where input comes in } else { inchar[0] = (char)is.read(); str1 = str1 + String.valueOf(inchar[0]); } } st1 = new StringTokenizer(str1, " ", false); while (!str1.equals("Sendmail")) str1 = st1.nextToken(); str1 = st1.nextToken(); System.out.println("Sendmail version: "+str1); System.out.print("Specify HELO? (y/n):"); str1 = dis.readLine(); if (str1.equals("y")){ System.out.print("HELO:"); str1 = dis.readLine(); os.write( ("HELO "+str1+"\r\n").getBytes()); str1 = ""; while (is.available() <= 0){} while (is.available() > 0) { if (is.available() > 9) { is.read(inbyte); for (int l2=0;l2<10;l2++) { inchar[l2] = (char)inbyte[l2]; str1 = str1 + String.valueOf(inchar[l2]); } //this is where input comes in } else { inchar[0] = (char)is.read(); str1 = str1 + String.valueOf(inchar[0]); } } System.out.println(str1); } System.out.print("Sender:"); str1 = dis.readLine(); os.write (("MAIL FROM: "+str1+"\r\n").getBytes()); while (is.available() <= 0){} while (is.available() > 0) { if (is.available() > 9) { is.read(inbyte); for (int l2=0;l2<10;l2++) { inchar[l2] = (char)inbyte[l2]; str1 = str1 + String.valueOf(inchar[l2]); } //this is where input comes in } else { inchar[0] = (char)is.read(); str1 = str1 + String.valueOf(inchar[0]); } } System.out.print("Recipient:"); str1 = dis.readLine(); os.write (("RCPT TO: "+str1+"\r\n").getBytes()); System.out.println("Data:"); str1 = ""; os.write ("DATA\r\n".getBytes()); while (!str1.equals(".")) { str1 = dis.readLine(); os.write ((str1+"\r\n").getBytes()); } os.write ("QUIT\r\n".getBytes()); sockit.close(); }catch (Exception e){} } catch (java.net.UnknownHostException e){ System.out.println ("Unknown host error!");} } catch (Exception e) {} } } //class Th1 implements Runnable { // private int va1; // InputStream is; // OutputStream os; // Th1 (InputStream is1, OutputStream os1) // {super(); // is = is1; // os = os1; // } //}