/**
* Class TestEmail
* @ Author yancheng (j-share.onchina.net)
* @ Version 1.0.0
*
* Use 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", 25 );
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 ("250") isOk = true;
Else isOk = false;
If (isOk ){
Ou. println ("rcpt to: ycshowtop@21cn.com ");
Instr = in. readLine ();
Out. println (instr );
If (instr. startsWith ("250") isOk = true;
Else isOk = false;
}
If (isOk ){
Ou. println ("DATA ");
Instr = in. readLine ();
Out. println (instr );
If (instr. startsWith ("250") isOk = true;
Else isOk = false;
}
Ou. println ("this is a test email ");
Ou. println (".");
Instr = in. readLine ();
Out. println (instr );
If (instr. startsWith ("250") 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 ()
{
}
}