Hi ,

I just jave this simple mail program that writes mail to external file.

How can I make this program so if the user wants to enter more e-mails he should be able to do it with some sort of loop structure,

Also How can I divide this class to two seperate classes so one should be doing information collection other one should be doing writing section in to the file.

Thanks,

CODE:

import java.io.*;



public class mailto {
public static void main(String[] args) {
// TODO Auto-generated method stub

String server="HELO mail.google.com";
String from = "";
String to = "";
String cc = "";
String bcc= "";
String replyto="";
String subject1 = "";
String emailText = "";
PrintWriter myOutput;





for (int i = 0; i < args.length; i++) {
if (args[i].toLowerCase().startsWith("from:")) {

from = args[i].toLowerCase().substring("from:".length());


} else if(args[i].toLowerCase().startsWith("to:")) {

to = args[i].toLowerCase().substring("to:".length());


}else if(args[i].toLowerCase().startsWith("subject:")) {


subject1 = args[i];



} else if (args[i].toLowerCase().startsWith("cc:")){

cc = args[i].toLowerCase().substring("cc:".length());


}else if (args[i].toLowerCase().startsWith("bcc:")){

bcc = args[i].toLowerCase().substring("bcc:".length());


}
else if (args[i].toLowerCase().startsWith("replyto:")){

replyto = args[i].toLowerCase().substring("replyto:".length());


}





else if (args[i].toLowerCase().startsWith("body:"))

{ //The rest



for (int j = i; j < args.length; j++)
{

emailText += args[j].concat(" ");
}

emailText = emailText.substring(0, emailText.length()-1).substring("body:".length());


try {
FileOutputStream fos = new FileOutputStream("MyFile.txt");
myOutput = new PrintWriter(fos, true);
myOutput.println(server);
myOutput.println("MAIL FROM:" + from.toLowerCase());

String [] addrs = to.split(",");
for (int k = 0; k < addrs.length; k++)
{

myOutput.println("RCPT TO:"+ addrs[k].toLowerCase());


}

String [] addrs1 = cc.split(",");


for (int l = 0; l < addrs1.length; l++)
{

if(addrs1[l] != null && !addrs1[l].equals("") ){
myOutput.println("CC:" + addrs1[l].toLowerCase());
}

}


String [] addrs2 = bcc.split(",");

for (int m = 0; m < addrs2.length; m++)
{
if (addrs2[m] != null && !addrs2[m].equals("") ){
myOutput.println("BCC:" + addrs2[m].toLowerCase());

}

}
myOutput.println("DATA");
myOutput.println("Subject:" + subject1.substring("subject:".length()));


String [] addrs3 = replyto.split(",");
for (int j = 0; j < addrs3.length; j++)
{
if (addrs3[j] != null && !addrs3[j].equals("")){
myOutput.println("Reply To:" + addrs3[j].toLowerCase());

}
}
myOutput.println("");
myOutput.println(emailText);
myOutput.println(".");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



}
}
}
}