|
-
sending mail thro' smtp server
I am trying to send mail thro' smtp server but i am getting mail with no body
kindly help
I am pasting the code also
import java.io.*;
import java.net.*;
public class processMessage {
static PrintWriter streamOut;
static DataInputStream dis;
public processMessage()
{
String HELO = "HELO ";
String MAIL_FROM = "mail from:anjuagg@hotmail.com";
String RCPT_TO = "rcpt to:anjua@niit.com";
String DATA = "data";
String SUBJECT = "subject:Subject goes here";
String BODY = "Message goes here" +"\n.\nquit";
String QUIT = "quit";
Socket smtp = null;
try{
System.out.println("in the constructor");
smtp = new Socket("mail2.niit.com",25);
OutputStream os = smtp.getOutputStream();
streamOut = new PrintWriter(os,true);
InputStream is = smtp.getInputStream();
dis = new DataInputStream(is);
}
catch (IOException e){
System.out.println("Error connecting: "+e);
}
try{
String loc = InetAddress.getLocalHost().getHostName();
send(HELO +loc);
receive();
send(MAIL_FROM);
receive();
send(RCPT_TO);
receive();
send(DATA);
receive();
send(SUBJECT);
receive();
send(BODY);
receive();
receive();//get closing response
smtp.close();
}
catch (IOException e){
System.out.println("Error sending: "+e);
}
System.out.println("Message Sent!");
}
public static void main(String args[])
{
System.out.println("1");
processMessage pro = new processMessage();
System.out.println("2");
}
public static void send(String str) throws IOException {
streamOut.write(str+"\n");
streamOut.flush();
System.out.println("Java sent: "+str);
}
public static void receive() throws IOException {
String readstr = dis.readLine();
System.out.println("SMTP Response: "+readstr);
}
}
regards
anju
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