Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Send email using IMAP , what changes my code need to do authentication ?

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
thank you for reading my post
here is my code to send email using SMTP , now i want to change this code to send email using IMAP and it should be authenticated , does any one know which changes i should introduce in this code ?

thanks
 
siva kumar
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

For reading messages from IMAP server use the following code-snippet below

Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("IMAP");
store.connect(host, username, password);
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
Message[] messages = inbox.getMessages( );

If you need to use POP3 protocol then change the code

Store store = session.getStore("POP3");

Please note I think folder concept does not apply to POP3 protocols

And further more as far as I know one does not need to provide user-name and password for sending mails, Auth info is gendrally required for reading mails, but some mail servers may have security restrictions which may require auth info even for sending mails
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sivaram's answer about how to read messages from IMAP and POP3 servers is certainly correct, but it fails to mention how to send messages using those servers.

That's because you can't send messages using those servers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic