java socket smtp_JAVA Socket实现smtp发送邮件

MAIN函数:Socketsocket=newSocket();LogPrinter.setConnectTime(socket,"66.96.163.96",25);方法:publicstaticvoidsetConnectTime(Socketsocket,Stringname,intport){SocketAddress...

MAIN函数:

Socket socket = new Socket();

LogPrinter.setConnectTime(socket,"66.96.163.96",25);

方法:

public static void setConnectTime(Socket socket, String name, int port) {

SocketAddress address = new InetSocketAddress(name, port);

try {

long start = System.currentTimeMillis();

socket.connect(address);

System.out.println("连接成功-" + socket.getInetAddress() + " : "

+ (System.currentTimeMillis() - start) + "ms");

PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

BufferedReader input = new BufferedReader(new InputStreamReader(

System.in));

BufferedReader read = new BufferedReader(new InputStreamReader(

socket.getInputStream()));

String line = null;

String line1 = null;

while ((line = read.readLine()) != null) {

System.out.println(line);

// System.out.println(line1 = input.readLine());

out.println(input.readLine());

}

} catch (BindException e) {

System.out.println("BindException-无法绑定本地IP或端口");

} catch (UnknownHostException e) {

System.out.println("UnknownHostException-无法识别该地址或IP:" + name);

} catch (ConnectException e) {

System.out.println("ConnectException-无法连接指定端口:" + port);

} catch (SocketException e) {

System.out.println("SocketException-连接超时");

} catch (IOException e) {

System.out.println("IOException");

}

finally {

if (socket != null) {

try {

socket.close();

} catch (IOException e) {

System.out.println("关闭Socket失败");

}

}

}

根据对方发过来的提示填写信息 (完全按照书上的操作 但回执信息不同 )

应该怎么正确填写? 求正常运行的方法 只要能发出去就行

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值