Socket socket = new Socket(JOptionPane
.showInputDialog("Your SMTP server name?"), 25);
BufferedReader in = new BufferedReader(new InputStreamReader(socket
.getInputStream(), "8859_1"));
BufferedWriter out = new BufferedWriter(new
OutputStreamWriter(socket
.getOutputStream(), "8859_1"));
String boundary = "DataSeparatorString";
for (String s : new String[] { "HELO theWorld",
"MAIL FROM: <i...@users.sourceforge.net>",
"RCPT TO: <i...@users.sourceforge.net>", "DATA" }) {
out.write(s + "\r\n");
out.flush();
s = in.readLine();
}
for (String s : new String[] { "MIME-Version: 1.0",
"Content-Type: multipart/mixed; boundary=\"" + boundary + "\"",
"\r\n--" + boundary,
"Content-Type: text/plain; charset=\"us-ascii\"\r\n",
"test\r\n\r\n", "\r\n--" + boundary,
"\r\n\r\n--" + boundary + "--\r\n" }) {
out.write(s + "\r\n");
out.flush();
}
for (String s : new String[] { ".", "QUIT" }) {
out.write(s + "\r\n");
out.flush();
s = in.readLine();
}
socket.close();
System.exit(0);
The full source code for this example may be found here: