Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

send and read email

 
Abdoul Kader Soumahoro
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are absolutely right. I need help with the code
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nam Ha Minh
Ranch Hand
Posts: 502
Eclipse IDE Firefox Browser Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abdoul Kader Soumahoro
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you handling authentication in your code?
 
Abdoul Kader Soumahoro
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I am. below is the code maybe Im missing something.

 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic