aspose file tools*
The moose likes Servlets and the fly likes SmtpClient Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "SmtpClient" Watch "SmtpClient" New topic
Author

SmtpClient

sirisha pu
Greenhorn

Joined: Nov 03, 2003
Posts: 9
I am using SmtpClient to send a mail from a servlet .
The To: , From: , Subject headers work fine and the mail is sent but the message body does not reach.
piece of code used:
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOut);
SmtpClient mailer=new SmtpClient("Exchcorp");
mailer.from(from);
mailer.to(to);
java.io.PrintStream ps = mailer.startMessage();
//all strings are defined
ps.println("From: " +from);
ps.println("To: " +to );
ps.println("Subject: " +subject);
ps.println(body);
mailer.closeServer();
out.writeUTF("mail is sent");
out.flush();
Please help.........
regards,
suchitra
Anil aleti
Greenhorn

Joined: May 02, 2000
Posts: 9
please make sure that after writing body you have to send a blank
line before closing the connection. I too using SmtpClient but I did not face any problem.Still if you are not clear, i will send the whole code in the next reply.


aaa
sirisha pu
Greenhorn

Joined: Nov 03, 2003
Posts: 9
thanx for the prompt reply.
i have done that but yet the problem persists
suchitra
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I think you are missing the blank line between the headers and the message body. Without it, your whole message could be being treated as headers.

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Anil aleti
Greenhorn

Joined: May 02, 2000
Posts: 9
Remove following two lines of code from your program and try.
ps.println("From: " +from);
ps.println("To: " +to );

sirisha pu
Greenhorn

Joined: Nov 03, 2003
Posts: 9
Hi,
i tried both the options ,Frank and Anil, but it still does not work!I tried using startMessage() and closeMessage() but that to does not work .This seems quite simple but i am unable to figure out what is happening .I am using swing components and sending data to servlet from the applet and the mail server is Exchange 5.5
regards,
suchitra
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You can try setting the header from your Servlet
as
response.setContentType("text");
Moreover i would prefer first to flush data then to close mailserver as
ps.println(strData);
ps.flush();
ps.close();
sendmail.closeServer();
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
You need to send a blank line after the headers. So after the subject line i.e out.println("Subject" + sub) add another as out.println("\r\n");. This should solve your problem
santosh s
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi ,
thanx All
this Mail stuff really worked after putting a blank line after the subject
But there was also problem on my outlook configuration when i was testing.After running it form another machine it really worked!
But I don't find this smtpClient class very useful so now JavaMail Api will be better
regards,
suchitra
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SmtpClient