预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

编号:时间:2021年x月x日书山有路勤为径,学海无涯苦作舟页码:第页共NUMPAGES10页第PAGE\*MERGEFORMAT10页共NUMPAGES\*MERGEFORMAT10页javasocket实现SMTP协议发送邮件文章分类:Java编程packagecom.socket.test;importjava.io.BufferedReader;importjava.io.DataOutputStream;importjava.io.IOException;importjava.io.InputStreamReader;importjava.net.Socket;importjava.net.UnknownHostException;importcom.sun.org.apache.xerces.internal.impl.dv.util.Base64;/***通过socket向smtp协议服务器发送邮件*@authorfuyanqing**/publicclassSocketMail{StringmailServer;Stringfrom;Stringto;Stringcontent;StringlineFeet="\r\n";privateintport=25;Socketclient;BufferedReaderin;DataOutputStreamos;publicStringgetContent(){returncontent;}publicvoidsetContent(Stringcontent){this.content=content;}publicStringgetMailServer(){returnmailServer;}publicvoidsetMailServer(StringmailServer){this.mailServer=mailServer;}publicStringgetFrom(){returnfrom;}publicvoidsetFrom(Stringfrom){this.from=from;}publicStringgetTo(){returnto;}publicvoidsetTo(Stringto){this.to=to;}/***初始化连接*@return*/privatebooleaninit(){booleanboo=true;if(mailServer==null||"".equals(mailServer)){returnfalse;}try{client=newSocket(mailServer,port);in=newBufferedReader(newInputStreamReader(client.getInputStream()));os=newDataOutputStream(client.getOutputStream());StringisConnect=response();if(isConnect.startsWith("220")){}else{System.out.println("建立连接失败:"+isConnect);boo=false;}}catch(UnknownHostExceptione){System.out.println("建立连接失败!");e.printStackTrace();boo=false;}catch(IOExceptione){System.out.println("读取流失败!");e.printStackTrace();boo=false;}returnboo;}/***发送smtp指令*并返回服务器响应信息*/privateStringsendCommand(Stringmsg){Stringresult=null;try{os.writeBytes(msg);os.flush();result=response(