I'm trying to figure this out with out any Java experience. I'm trying to write a program that will send a SMTP email. I was given a shell and I do know how to establish a connection. My next question is how do I Send MAIL FROM command, Send RCPT TO command, Send DATA command, Send message data and End with line with a single period. Will this be just a matter or printing this information? Someone please help me figure this out.
Code:
import java.io.*;
import java.net.*;
public class EmailSender
{
public static void main(String[] args) throws Exception
{
// Establish a TCP connection with the mail server.
Socket TCPConnection = new TCPConnection("mail.bellsouth.net, 25");
// Create a BufferedReader to read a line at a time.
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
// Read greeting from the server.
String response = br.readLine();
System.out.println(response);
if (!response.startsWith("220")) {
throw new Exception("220 reply not received from server.");
}
// Get a reference to the socket's output stream.
OutputStream os = socket.getOutputStream();
// Send HELO command and get server response.
String command = "HELLO Nikki\r\n";
System.out.print(command);
os.write(command.getBytes("US-ASCII"));
response = br.readLine();
System.out.println(response);
if (!response.startsWith("250")) {
throw new Exception("250 reply not received from server.");
}
// Send MAIL FROM command.
// Send RCPT TO command.
// Send DATA command.
// Send message data.
// End with line with a single period.
// Send QUIT command.
}
}