Example of getting priority messages:
Example of sending a simple message:GmailConnection conn = new ImapGmailConnection(); //configure connection GmailClient client = new ImapGmailClient(); client.setConnection(conn); //set the {@code boolean} unreadOnly to {@code true} to retrive unread //priority messages only, {@code false} to read priority messages onlyList<GmailMessage> priorityMessages = client.getPriorityMessages(true);
Example of moving message(s) to the trash folder:GmailConnection conn = new ImapGmailConnection(); //configure connection GmailClient client = new ImapGmailClient(); client.setConnection(conn); GmailMessage message = new JavaMailGmailMessage(); message.setSubject("Hi!"); message.setContentText("A message from Gmail4J"); message.addTo(new EmailAddress("j.smith@example.com")); client.send(message);
Example of marking a message as read:GmailConnection conn = new ImapGmailConnection(); //configure connection GmailClient client = new ImapGmailClient(); client.setConnection(conn); List<GmailMessage> messages = client.getUnreadMessages(); client.moveToTrash(messages.toArray(new JavaMailGmailMessage[0]));
Example of marking all messages as read:GmailConnection conn = new ImapGmailConnection(); //configure connection GmailClient client = new ImapGmailClient(); client.setConnection(conn); List<GmailMessage> messages = client.getUnreadMessages(); // now get a GmailMessage item and pass it's message number client.markAsRead(message.getMessageNumber());
Example of marking a message as unread:GmailConnection conn = new ImapGmailConnection(); //configure connection GmailClient client = new ImapGmailClient(); client.setConnection(conn); client.markAllAsRead();
Example of flagging a message as starred:GmailConnection conn = new ImapGmailConnection(); //configure connection GmailClient client = new ImapGmailClient(); client.setConnection(conn); // now get a read GmailMessage item and pass it's message number client.markAsUnread(message.getMessageNumber());
Example of removing a message flagged as starred:GmailConnection conn = new ImapGmailConnection(); //configure connection GmailClient client = new ImapGmailClient(); client.setConnection(conn); // now get a GmailMessage item and pass it's message number client.addStar(message.getMessageNumber());
Example of message move to destination folder:GmailConnection conn = new ImapGmailConnection(); //configure connection GmailClient client = new ImapGmailClient(); client.setConnection(conn); // now get a GmailMessage item and pass it's message number client.removeStar(message.getMessageNumber());
@see GmailClient @see ImapGmailConnection @author Tomas Varaneckas <tomas.varaneckas@gmail.com> @version $Id: ImapGmailClient.java 62 2010-12-12 03:29:19Z rajivderas@gmail.com $ @since 0.3// Constructor with the source folder name ImapGmailClient client = new ImapGmailClient(ImapGmailLabel.SENT_MAIL); //configure connection GmailClient client = new ImapGmailClient(); client.setConnection(conn); // name the destination folder and the message # to be moved client.moveTo(ImapGmailLabel.SPAM, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|