Hi !
I am writing simple email client that uses TCP/IP sockets to interact with an SMTP server to send email messages.
this is my code

import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;  

public class TestSendMail {

  public static void main(String args[]) throws IOException {

     Socket socket;
     DataInputStream dataInput;
     DataOutputStream dataOutput;

     String mailServer = new String("smtp.gmail.com");

     socket = new Socket(mailServer, 587);
     dataInput = new DataInputStream( socket.getInputStream());
     dataOutput = new  DataOutputStream( socket.getOutputStream());

     String sender= "mymail@gmail.com";
     dataOutput.writeBytes("MAIL FROM: " + sender );
     System.out.println( dataInput.readLine() );

     String addressee= "friend@gmail.com";
     dataOutput.writeBytes("RCPT TO: " + addressee );
     System.out.println( dataInput.readLine() );

     dataOutput.writeBytes("DATA");
     System.out.println( dataInput.readLine() );

     dataOutput.writeBytes("This is the first line of testing message.");
     dataOutput.writeBytes("This is the second line of testing message.");
     dataOutput.writeBytes(".");
     System.out.println( dataInput.readLine() );

     dataOutput.flush();
     socket.close();
   }
}

when i am executing it prints only this line and cursor waits....
220 mx.google.com ESMTP x23sm19943471bkw.12

It is not proceeding further.
I dont know why.
Plz help me.

Are you using the correct protocol with the server? Did you send it the right messages? Are you sure it will send you more lines to read when you expect them to be sent or do you have to send more before the server will respond?

Edited 4 Years Ago by NormR1

If u can plz give me a url to study about this. Im confused with this.

Try google for the RFC on SMTP to get the definition for the SMTP protocol.

Edited 4 Years Ago by NormR1

This question has already been answered. Start a new discussion instead.