email without JavaMail

14 views
Skip to first unread message

Isaac4given

unread,
Aug 16, 2007, 11:20:26 AM8/16/07
to WITL (Walk In The Light)
If we're willing to do a little extra work to send the email, WITL
won't require the JavaMail API. Here's how:

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:

http://groups.google.com/group/witl/web/SendSMTP.java

Reply all
Reply to author
Forward
0 new messages