Networking Java Solutions Homework Open an SMTP connection to a remote machine and

Document Type
Homework Help
Book Title
Computer Networking: A Top-Down Approach 6th Edition
James F. Kurose, Keith W. Ross
Solution for the Mail Client Lab
import java.util.*;
/* $Id:,v 2003/09/30 14:36:01 kangasha Exp $ */
* Open an SMTP connection to a remote machine and send one mail.
* @author Jussi Kangasharju
public class SMTPConnection {
/* The socket to the server */
public Socket connection;
/* Streams for reading and writing the socket */
public BufferedReader fromServer;
public DataOutputStream toServer;
/* Just to make it look nicer */
private static final int SMTP_PORT = 25;
private static final String CRLF = "\r\n";
/* Are we connected? Used in close() to determine what to do. */
isConnected = true;
/* Close the connection. Try to send QUIT-commmand and then close
the socket. */
public void close() {
isConnected = false;
try {
sendCommand("QUIT", 221);
} catch (IOException e) {
System.out.println("Unable to close connection: " + e);
isConnected = true;
/* Send an SMTP command to the server. Check for reply code. Does
not check for multiple reply codes (required for RCPT TO). */
private void sendCommand(String command, int rc) throws IOException {
String reply = null;

Trusted by Thousands of

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.