Question: Write a smtp client program and smtp server program to inplement the following simplified smtp protocol based on the tcp service and make sure the

Write a smtp client program and smtp server program to inplement the following simplified smtp protocol based on the tcp service and make sure the programSupports mulltiple clientes.

import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; import java.net.ServerSocket; import java.net.Socket;

public class Server {

public static void main(String[] args) throws Exception { System.out.println("Stablishing connection"); ServerSocket server = new ServerSocket(25); System.out.println("guardando concexion."); Socket socket = server.accept(); System.out.println("conexion establecida."); InputStream input = socket.getInputStream(); OutputStream output = socket.getOutputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(input)); PrintStream out = new PrintStream(output); while (true){ String mensagem = in.readLine(); System.out.println( "Mensagem recebida do cliente [" + socket.getInetAddress().getHostName() + "]: " + mensagem); if ("FIM".equals(mensagem)){ break; } out.println(mensagem); } System.out.println("Encerrado servidor"); in.close(); out.close(); socket.close(); System.out.println("Encerrado servidor"); server.close(); } }

========================================================

import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; import java.net.Socket; import java.util.Properties; import java.util.Scanner; import javax.mail.Message; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage;

public class Client { public static BufferedReader in; public static PrintStream out; public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(System.in); System.out.println("Enter the HostName (or ip address) of your SMTP server"); String ipAddress = scanner.nextLine(); //Buildup the TCP connection to your smtp server System.out.println("stablishing connection"); System.out.println("Initializing connection with the servidor."); try { Socket socket = new Socket(ipAddress, 25);//aqio en puerto va ipaddress System.out.println("Connection stablished");

InputStream input = socket.getInputStream(); OutputStream output = socket.getOutputStream();

BufferedReader in = new BufferedReader(new InputStreamReader(input)); PrintStream out = new PrintStream(output); //printstream para guardar strings.podemos leer mjs de cliente /** * Wait for, read and display a 220 response from he SMTP server * */ while(true) { System.out.println("Digito mimensaje para mandarlo a servidor.| 220 smtp.server.com Simple Mail Transfer Service Ready "); String mensagem = scanner.nextLine(); out.println(mensagem); if("FIM".equals(mensagem)){ break; } mensagem = in.readLine(); System.out.println( "mensagem recibido do servodor: " + mensagem); } } catch (Exception e) {// esto es igual q cachar UnknownHostException System.out.println("The given Enter the HostName (or ip address) of " + "your SMTP server, was not recognized " + ipAddress); System.exit(0);//a nonzero indica abnormal condicion }

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!