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失敗");
}
}
}
根據對方發過來的提示填寫信息 (完全按照書上的操作 但回執信息不同 )
應該怎么正確填寫? 求正常運行的方法 只要能發出去就行
展開
總結
以上是生活随笔為你收集整理的java socket smtp_JAVA Socket实现smtp发送邮件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 光速破发?iPhone 14黄色版还未开
- 下一篇: NASA 美国宇航局 2024 年预算