最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
在servlet中直接写端口发送邮件的例子
时间:2022-07-02 17:55:08 编辑:袖梨 来源:一聚教程网
/**
*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("TestEmail ");
out.println("");
String instr = null;
boolean isOk = false;
try{
ou.println("HELO:smtp.163.net");
out.println(in.readLine());
ou.println("MAIL FROM:[email protected]");
instr = in.readLine();
out.println(instr);
if(instr.startsWith("250")) isOk = true;
else isOk=false;
if(isOk){
ou.println("RCPT TO:[email protected]");
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("这是一个测试邮件");
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("
out.println("");
}
public void destroy()
{
}
}
*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("");
String instr = null;
boolean isOk = false;
try{
ou.println("HELO:smtp.163.net");
out.println(in.readLine());
ou.println("MAIL FROM:[email protected]");
instr = in.readLine();
out.println(instr);
if(instr.startsWith("250")) isOk = true;
else isOk=false;
if(isOk){
ou.println("RCPT TO:[email protected]");
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("这是一个测试邮件");
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("
ok
");out.println("");
}
public void destroy()
{
}
}
相关文章
- 以闪亮之名店长体验流霞季怎么玩 缘溪临霞套装活动介绍 12-31
- 未定事件簿旧梦新生左然篇怎么玩 旧梦新生左然篇活动介绍 12-31
- 未定事件簿左然破浪远行怎么样 12-31
- 桃源深处有人家行医问诊怎么玩 12-31
- 恋与制作人跨年福利有哪些 恋与制作人跨年福利内容介绍 12-31
- 阴阳师协同对弈大乱斗怎么玩 阴阳师协同对弈大乱斗活动介绍 12-31