aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes send and read email Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "send and read email" Watch "send and read email" New topic
Author

send and read email

Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
Dear All, 
Any one guide me, I really need some help to send mail with multiple attachments read them and then move the read email to another folder. Im using James server but I really don't know how to accomplish this. Thank you.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

You don't use the e-mail server to do any of that. Of course you need an e-mail server to handle incoming mail and outgoing mail, but if you want to send mail and read received mail then you need to write code using JavaMail.
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
You are absolutely right. I need help with the code
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
Are you familiar with JavaMail? If not, you can find introductions, FAQs, code samples and more in the https://www.coderanch.com/how-to/java/JavaEnterpriseEditionFaq


Ping & DNS - my free Android networking tools app
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

Abdoul Kader Soumahoro wrote:Dear All, 
Any one guide me, I really need some help to send mail with multiple attachments read them and then move the read email to another folder. Im using James server but I really don't know how to accomplish this. Thank you.


Hi Abdoul Kader Soumahoro,

Here are some examples using JavaMail you may need:

- Send e-mail with attachment in Java
- Download attachments in e-mail messages using JavaMail

Hope this helps.


PM Me If You Want to get Urgent Help on Java Programming
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
Thanks Nam! That really help... I can send however I cannot read. I keep getting the following error.

Could not connect to the message store
javax.mail.AuthenticationFailedException: Authentication failed.
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:207)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:196)
at com.jpmc.jamesserver.ReadingEmail.downloadEmailAttachments(ReadingEmail.java:55)
at com.jpmc.jamesserver.ReadingEmail.main(ReadingEmail.java:141)


I am using "localhost" as my host and port "110"
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
How are you handling authentication in your code?
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
Yes I am. below is the code maybe Im missing something.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

Abdoul Kader Soumahoro wrote:Yes I am.


By this do you mean "Yes I am handling authentication?" I ask because I don't see any code which does that. Could you point out the lines of code which you think deal with authentication?

(You can use the line numbers to do that. Notice that I edited your code to use the code tags so that it becomes readable code -- read the page at UseCodeTags to find out how to do that in future.)
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
From my understanding everything is all handled in the "try" starting at line 50. I honestly didnt write this code and I'm trying to understand it and make it work for me. I'm a beginner in java so I kinda need help to figure this out.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

Oh, I see. Sorry. Your attempt at authentication is here:



So make sure you're using a user name which your server recognizes, and the correct password. Here's where you set the user name which you pass to the server:



Is that really the user name configured into your server? It looks a bit strange to me, but then I know nothing about how you (or whoever it was) set up your server.
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
I installed james server on my machine and added a few users and "user" is one of them... I am testing (send and receive emails) locally so user@localhost is a valid user. I actually tried with the others users I created but Im still getting the same error.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

If you're saying that "user" is one of the user names you configured, then why are you using "user@localhost" in your Java code?
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
You know what you are right!!! I don't what I was thinking. I just changed String userName = "user"; and it works now!!! Thank you so much!!!
Abdoul Kader Soumahoro
Greenhorn

Joined: Aug 28, 2013
Posts: 22
However I noticed that output is not ordered by date. Below is output... (Can you please take a look at the sent date for the emails...)

Message #1:
From: user@localhost
Subject: New email with attachments2
Sent Date: Sat Sep 14 23:28:44 EDT 2013
Message: I have some attachments for you again.
Attachments: Attachment1.txt, Attachment2.txt, Attachment3.txt

Message #2:
From: user@localhost
Subject: New email with attachments3
Sent Date: Sat Sep 14 23:38:01 EDT 2013
Message: I have some attachments for you again for the third time.
Attachments: Attachment1.txt, Attachment2.txt, Attachment3.txt

Message #3:
From: user@localhost
Subject: New email with attachments
Sent Date: Sat Sep 14 23:06:24 EDT 2013
Message: I have some attachments for you.
Attachments: Attachment1.txt, Attachment2.txt, Attachment3.txt

Message #4:
From: user@localhost
Subject: New email with attachments - 09/15/13
Sent Date: Sun Sep 15 20:05:33 EDT 2013
Message: I have updated the attachments content. Check it out!
Attachments: Attachment1.txt, Attachment2.txt, Attachment3.txt

Message #5:
From: user@localhost
Subject: New email with attachments3
Sent Date: Sun Sep 15 17:12:27 EDT 2013
Message: I have some attachments for you again for the third time.
Attachments: Attachment1.txt, Attachment2.txt, Attachment3.txt

Thank you again!
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1067
    
  10

Abdoul Kader Soumahoro wrote:However I noticed that output is not ordered by date. Below is output...


Unless I am missing something, it seems that all you have to do it sort them yourself !
 
Consider Paul's rocket mass heater.
 
subject: send and read email