Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.nio.ByteBuffer;
- import java.nio.charset.StandardCharsets;
- public class SMTPServer {
- public static void main(String[] args) {
- while (true) {
- try (ServerSocket serverSocket = new ServerSocket(25)) {
- Socket client = serverSocket.accept();
- System.out.println("Accepted!");
- BufferedReader clientIn = new BufferedReader(new InputStreamReader(client.getInputStream()));
- BufferedWriter clientOut = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
- clientOut.write("220 OK\r\n");
- clientOut.flush();
- String inputLine;
- char[] buffer = new char[1024];
- int count;
- while ((count = clientIn.read(buffer)) != -1) {
- System.out.println(buffer);
- clientOut.write("250 OK\r\n");
- clientOut.flush();
- }
- clientOut.write("250 OK\r\n");
- clientOut.flush();
- inputLine = clientIn.readLine();
- System.out.println(inputLine);
- inputLine = clientIn.readLine();
- System.out.println(inputLine);
- inputLine = clientIn.readLine();
- System.out.println(inputLine);
- inputLine = clientIn.readLine();
- System.out.println(inputLine);
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement