views:

58

answers:

2

how can i access gmail emails using sinetfactory api. please provide an example

A: 

Just use documentation, which is in html folder of sinetfactory. Everything is there.

import com.jscape.inet.imap.*;
import com.jscape.inet.email.*;
import com.jscape.inet.imapssl.ImapSsl;
import com.jscape.inet.mime.*;
import java.io.*;

public class ImapSshExample {
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));;

    public void getMessages() throws ImapException, MimeException, IOException {

        ImapSsl imap = new ImapSsl("imap.gmail.com", 993, "username", "password");
        imap.connect();
        int messageCount = imap.getMessageCount();

        for (int i = 1; i <= messageCount; i++) {
            EmailMessage msg = imap.getMessage(i);
            System.out.println("-- begin message --");
            System.out.println(new String(msg.getMessage()));
            System.out.println("-- end message --");

            System.out.print("ENTER for next message or type QUIT to quit: ");
            String command = reader.readLine();
            if (command.equalsIgnoreCase("quit")) {
                break;
            }
        }
        imap.disconnect();
    }

    public static void main(String[] args) {
        try {
            ImapSshExample example = new ImapSshExample();
            example.getMessages();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Nightsorrow
but how can i access emails that are new or unread.
S M ADIL
A: 

Heeey, look in to the documentation :) This is how you can get new messages:

// get messages in mailbox
Enumeration e = imap.getNewMessages();

// loop thru all messages in mailbox
while(e.hasMoreElements()) {
EmailMessage message = (EmailMessage)e.nextElement();
// print out subject, or do what you want
System.out.println(message.getSubject());
Nightsorrow