-
Java Se mail program question
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();
}
}
}
}
}
Similar Threads
-
By zobi316 in forum VB Classic
Replies: 3
Last Post: 03-10-2008, 07:05 AM
-
Replies: 1
Last Post: 06-12-2006, 11:20 AM
-
Replies: 2
Last Post: 04-30-2006, 09:08 AM
-
By Glen Kunene in forum Talk to the Editors
Replies: 17
Last Post: 03-23-2002, 12:43 AM
-
By JJ in forum Enterprise
Replies: 1
Last Post: 07-06-2000, 04:50 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks