开发者

how to access gmail mails using sinetfactory api. please provide an example

开发者 https://www.devze.com 2022-12-17 03:10 出处:网络
how can i access gmail emails using sinetfactory api. please provide an exa开发者_开发技巧mpleJust use documentation, which is in html folder of sinetfactory. Everything is there.

how can i access gmail emails using sinetfactory api. please provide an exa开发者_开发技巧mple


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();
        }
    }
}


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());
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号