• Post Reply Bookmark Topic Watch Topic
  • New Topic

Read mail using Java mail API  RSS feed

 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Can any one tell me how to download emails from gmail and save into any local directory using java mail API.

I just know how to download the attachment from mail but I need to download the complete email.

Thanks in advance .
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you can already get the Message objects and read their attachments? If so, then Message inherits a writeTo method from Part that takes an OutputStream which you can use.
 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,
Thanks for reply,

Actuly I want to read the mail from my webmail(official mail).

to get from gmail we use below code.

Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");

Session session = Session.getInstance(props, null);
Store store = session.getStore();
store.connect("imap.gmail.com", "@gmail.com", "e*****");
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
Message msg = inbox.getMessage(inbox.getMessageCount());

but if i want to connect my webmail ,wht are the changes I need to update in the below line of code.

store.connect("imap.gmail.com", "@gmail.com", "e*****");

URL :- https://webmail.companyname.com.my/owa/
username :- test
password:-test123

my objective is to read mail from my webmail account
 
Paul Clapham
Sheriff
Posts: 22505
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You replace those things by whatever your web-mail provider tells you. That's provided they even allow access to their mail system via IMAP, which is not guaranteed. So call them up and ask how to access their mail system via IMAP.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!