File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes JavaMail: Help with sending e-mails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JavaMail: Help with sending e-mails" Watch "JavaMail: Help with sending e-mails" New topic

JavaMail: Help with sending e-mails

David Houghton

Joined: Jan 11, 2009
Posts: 19
Hi people, any help here would be great. Just so you know, this is my first venture into the JavaMail API. When i run my class below, a javax.mail.MessagingException is thrown, with the outptu [EOF]

Any ideas on why this is happening would be great. The trans connection to the smtpServer seems to be working fine, it is the sendMessage() method which i s throwing the exception

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Inserting a call to " session.setDebug(true) " will cause lots of info about what's happening to be written to standard out; often that includes something that points to the problem.
David Houghton

Joined: Jan 11, 2009
Posts: 19
Thanks Ulf, i identified the problem using the session debug. My coding was fine, i was trying to test it with an e-mail address using the worng protocol to connect to the server (i think!) Anyways, i am able to send e-mail via SMTP which is great.

I am however having a problem with retrieiving message from the server. I am able to retreive unread messages, but not read messages. the call to folder.getMessages() only seems to be retrieving unread messages

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

If you're going to be working with JavaMail, and you don't know much about how e-mail works, I would recommend you have a read through the JavaMail FAQ. The question you have asked is one of the many which is answered there.
David Houghton

Joined: Jan 11, 2009
Posts: 19
Thanks Paul ive had a read through the FAQs. Ive found out that my messages are deleted from my server once they have been retrieved, which is why i cannot retrieve unread messages!

I though i had found a way around this using message FLAGS, but ive just read that pop3 doesnt support flags!

Would i be write in saying that the only way to access read e-mails would be to store them on the client machine once read?


I agree. Here's the link:
subject: JavaMail: Help with sending e-mails
It's not a secret anymore!