Hey all

I have an assignment for university where we have to write a program to simulate an IDS. Basically how it works is the user enters a code and the program displays a relevant message. If a specific code is entered, an e-mail must be sent to the adminsitrator (in this case me). We aren't allowed to use JavaMail API.

Here's the code I have for sending the e-mail. The recipient address loony064@hotmail.com, the sending address is loony064@gmail.com and the smtp settings for gmail is smtp.gmail.com.

private String toEmailAddress = "loony064@hotmail.com";
private String mailServer = "smtp.gmail.com";

private void email(String message, int code)
{
// send e-mail to administrator
String subject = message;
String content = "";

// code relevant to actually getting the content of the message goes here

Socket socket = new Socket(mailServer, 25);
BufferedReader in = new BufferedReader(new InputStreamReader
                                                      (socket.getInputStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter  
                                                      (socket.getOutputStream()));
		
 // message 
send(in, out, "HELO gmail.com");
send(in, out, "MAIL FROM: Laura Unterslak <loony064@gmail.com>");
send(in, out, "RCPT TO: " + toEmailAddress);
send(in, out, "DATA");
send(out, "Subject: " + subject);
send(out, "From:  Laura Unterslak <loony064@gmail.com>");
		      
// message body
send(out, content);
send(in, out, "QUIT");
		      
 // close connection
socket.close();
} // end of void email

public void send(BufferedReader in, BufferedWriter out, String s) 
{
   try 
   {
      out.write(s + "\n");
      out.flush();
      System.out.println(s);
      s = in.readLine();
      System.out.println(s);
   }
   catch (Exception e) 
   {
      e.printStackTrace();
   }
 } // end send(BufferedReader in, BufferedWriter out, String s)

 public void send(BufferedWriter out, String s) {
   try 
   {
      out.write(s + "\n");
      out.flush();
      System.out.println(s);
   }
   catch (Exception e) 
   {
      e.printStackTrace();
   }
 } // end send(BufferedWriter out, String s)

The HELO and MAIL FROM commands are fine, but RCPT TO, DATA and QUIT give the following code and message:

530 5.7.0 must issue a STARTTLS command first. I assume this has something to do with Gmail requiring some sort of authentication but I'm not exactly sure. I haven't been able to find a way to fix this error except for when it occurs using the JavaMail API.

I'd appreciate any help or advice as to how i can resolve this

Yours truly
Laura

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.