import java.io.*;
import java.net.*;
public class mchookMailTest {
private static PrintStream ps = null;
private static DataInputStream dis = null;
public static void main (String args[]){
String HELLO = "HELLO ";
String MAIL_FROM = "MAIL FROM: ";
String RCPT_TO = "RCPT TO: ";
String SUBJECT = "SUBJECT: Test Message from mchookMailTest";
String DATA = "DATA";
String BODY = "mchookMailTest message!
.
";
// "
.
" - indicates the end of the message
Socket smtp = null;
try {
smtp = new Socket("smtp.any.com", 25);
OutputStream os = smtp.getOutputStream();
ps = new PrintStream(os);
InputStream is = smtp.getInputStream();
dis = new DataInputStream(is);
} catch (IOException e) {
System.out.println("Error connecting: " + e);
}
try {
String loc = InetAddress.getLocalHost().getHostName();
send(HELO + loc);
receive();
send(MAIL_FROM);
receive();
send(RCPT_TO);
receive();
send(DATA);
receive();
send(SUBJECT);
receive();
send(BODY);
receive();
smtp.close();
} catch (IOException e) {
System.out.println("Error sending:" + e);
}
System.out.println("Mail sent!");
}
public static void send(String str) throws IOException {
ps.println(str);
ps.flush();
System.out.println("Java sent: " + str);
}
public static void receive() throws IOException {
String readstr = dis.readLine();
System.out.println("SMTP response: " + readstr);
}
}
http://www.pate.ru/index.php?message=187