Question
Java program (the image got cut off so here is the full code:) import java.io.*; import java.net.*; public class EmailSender { public static void main(String[]
Java program
(the image got cut off so here is the full code:) import java.io.*;
import java.net.*;
public class EmailSender
{
public static void main(String[] args) throws Exception
{
// Establish a TCP connection with the G mail server.
Code Goes Here
// 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 = "HELO x ";
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.
Code Goes Here
// Send RCPT TO command.
Code Goes Here
// Send DATA command.
Code Goes Here
// Send message data.
//(Do not forget to include header lines, e.g., To: From: Subject:
//Please send me your section num(03 or 09), YOUR _NAME, and your Project Topic or Title.
Code Goes Here
// End with line with a single period.
Code Goes Here
// Send QUIT command.
Code Goes Here
}
}
Java provides an API for interacting with the Internet mail system, which is called JavaMail. However, we will not be using this API, because it hides the details of SMTP and socket programming. Instead, you should write a Java program that establishes a TCP connection with a mail server through the socket interface, and sends an email message *Create a Java file named EmailSender.java. Below is the shell of the code, but you will need to read the step before using code as it contains important server and client information Mai Server: gmail-smtp-in.lgoogle.com Port 25 From: youremailnortheastern.e du To: yourgamil@gmail.com This means you wil include in your code the details of the particular email message you are trying to send. Here is a skeleton of code you'l need to write: import java io.*. import java.net.*. public class EmailSender public static void main(String[] args) throws Exception / Establish a TCP connection with the Gmail server Code Goes Here // Create a BufferedReader to read a line at a time InputStream is = socket.getlnputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br new BufferedReader(isr)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started