Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

smtp mail using socket(mail content is not displaying)

843790Aug 13 2008 — edited Aug 14 2008
hi
I created a mail client using sockets.But the received mail doestnot show the mail body.code is given below.
import java.net.*;
import java.io.*;
import java.util.*;

public class EmailClient implements Runnable {

private Socket sc;
private InputStream is;
private OutputStream os;


private String from, to, subject, msg;

public EmailClient
(String from, String to, String subject, String msg) {
// parent = m;
this.from = from;
this.to = to;
this.subject = subject;
this.msg = msg;

}

public void run() {

try {System.out.println("hai");
sc=new Socket("hostname",25);

//sc = (Socket)Connector.open("socket://"+smtpServerAddress+":25");
is = sc.getInputStream();
os = sc.getOutputStream();

os.write(("HELO www.marinebiztv.com"+ "\r\n").getBytes());
os.write(("MAIL FROM: "+ from +"\r\n").getBytes());
os.write(("RCPT TO: "+ to + "\r\n").getBytes());

os.write("DATA\r\n".getBytes());
// stamp the msg with date
os.write(("Date: " + new Date() + "\r\n").getBytes());
os.write(("From: "+from+"\r\n").getBytes());
os.write(("To: "+to+"\r\n").getBytes());

os.write(("Subject: "+subject+"\r\n").getBytes());

os.write(("Hai hw r u\r\n").getBytes()); // message body
os.write(".\r\n".getBytes());
os.write("QUIT\r\n".getBytes());


// debug
StringBuffer sb = new StringBuffer();
int c = 0;
while (((c = is.read()) != -1) ) {
sb.append((char) c);
}
System.out.println(sb);
} catch(IOException e)
{


}
finally
{
try
{
if(is != null)
{
is.close();
}
if(os != null)
{
os.close();
}

}catch(Exception e){}
}

}


public static void main(String args[])
{
EmailClient email=new EmailClient("from","to","subject","message");
System.out.println("hai");
Thread t = new Thread(email);
t.start();
}
}
can anyone tell me whats the problem?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 11 2008
Added on Aug 13 2008
22 comments
426 views