servlet| Send mail/**
*class Testemail
* @author Yancheng (j-share.onchina.net)
* @version 1.0.0
*
* Use the write socket to send email.
*/
Import javax.servlet.*;
Import javax.servlet.http.*;
Import java.io.*;
Import java.util.*;
Import java.net.*;
Public class Testemail extends HttpServlet
{
private static final String Content_Type = "text/html";
public void init (ServletConfig config) throws servletexception
{
Super.init (config);
}
public void doget (HttpServletRequest request, httpservletresponse response)
throws Servletexception, IOException
{
Response.setcontenttype (content_type);
PrintWriter out = Response.getwriter ();
Socket s = new socket ("smtp.163.net");
PrintWriter ou = new PrintWriter (S.getoutputstream (), true);
BufferedReader in = new BufferedReader (New InputStreamReader (S.getinputstream ()));
Out.println (" Out.println (" Out.println ("<body>");
String instr = null;
Boolean isOk = false;
try{
ou.println ("helo:smtp.163.net");
Out.println (In.readline ());
Ou.println ("MAIL from:showtop@163.net");
InStr = In.readline ();
Out.println (instr);
if (Instr.startswith ("isOk")) = true;
else Isok=false;
if (isOk) {
Ou.println ("RCPT to:ycshowtop@21cn.com");
InStr = In.readline ();
Out.println (instr);
if (Instr.startswith ("isok=true"));
else IsOk = false;
}
if (isOk) {
Ou.println ("DATA");
InStr = In.readline ();
Out.println (instr);
if (Instr.startswith ("isOk")) = true;
else Isok=false;
}
Ou.println ("This is a test email");
Ou.println (".");
InStr = In.readline ();
Out.println (instr);
if (Instr.startswith ("isok=true"));
else Isok=false;
Ou.println ("QUIT");
S.close ();
}
catch (IOException x)
{
X.printstacktrace (System.err);
}
Out.println ("<p>ok</p>");
Out.println ("</body>}
public void Destroy ()
{
}
}