Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29767

How email server communicate to each others and their clients using SMTP protocol?

$
0
0

I am trying to understand how Email server works. Running the bellow Java code on port 25 I suppose it listens to a message sent to the port 25 which I suppose follows SMTP protocol thus emails are sent to my server through that port, where content format can be either text or other email. The idea is just to understand how to email server communicates with other servers and then email clients. So if my IP address is maybe 192.168.23.10 so other email servers can send emails to my server with the address as user@[192.168.2.1] or is there any additional thing needed?

I know there are securities and other things to consider but I would like to understand how this basically works just to get started with it.

TimeServer.javaTo run it:

java TimeServer 25
import java.io.*;import java.net.*;import java.util.Date;/** * This program demonstrates a simple TCP/IP socket server. * * @author www.codejava.net */public class TimeServer {    public static void main(String[] args) {        if (args.length < 1) return;        int port = Integer.parseInt(args[0]);        try (ServerSocket serverSocket = new ServerSocket(port)) {            System.out.println("Server is listening on port "+ port);            while (true) {                Socket socket = serverSocket.accept();                System.out.println("New client connected");                OutputStream output = socket.getOutputStream();                PrintWriter writer = new PrintWriter(output, true);                writer.println(new Date().toString());            }        } catch (IOException ex) {            System.out.println("Server exception: "+ ex.getMessage());            ex.printStackTrace();        }    }}

TimeClient.javaTo run:

java TimeClient localhost 25
import java.net.*;import java.io.*;/** * This program demonstrates a simple TCP/IP socket client.**/public class TimeClient {    public static void main(String[] args) {        if (args.length < 2) return;        String hostname = args[0];        int port = Integer.parseInt(args[1]);        try (Socket socket = new Socket(hostname, port)) {            InputStream input = socket.getInputStream();            BufferedReader reader = new BufferedReader(new InputStreamReader(input));            String time = reader.readLine();            System.out.println(time);        } catch (UnknownHostException ex) {            System.out.println("Server not found: "+ ex.getMessage());        } catch (IOException ex) {            System.out.println("I/O error: "+ ex.getMessage());        }    }}

Viewing all articles
Browse latest Browse all 29767

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>