Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SmtpClient

 
sirisha pu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sirisha pu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx for the prompt reply.
i have done that but yet the problem persists
suchitra
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anil aleti
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove following two lines of code from your program and try.
ps.println("From: " +from);
ps.println("To: " +to );

 
sirisha pu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic