|
import com.intrinsyc.cdo.*;
import com.linar.jintegra.Cleaner;
public class ForwardCopyMoveMessage {
public static void main(String[] args) {
// TODO: Change the following parameters based on your setup and configuration
// the logon parameters of the service account you used to configure CDO
String domain = "domain";
String username = "username";
String password = "password";
// the DNS name or IP address of the machine where you installed CDO
String CDOmachine = "0.0.0.0";
// the DNS name or IP address of the Exchange Server
String exchangeServer = "0.0.0.0";
// the mailbox you wish to access (NOTE: this is the same as the user's login name
// e.g., if the username is jsmith, mailbox would also be jsmith )
String mailbox = "mailbox";
try {
// use credentials of service account to authenticate to Windows.
com.linar.jintegra.AuthInfo.setDefault(domain, username, password);
// create a Session in the CDOmachine.
Session session = new Session(CDOmachine);
// logon to the Exchange Server.
session.logon(null, null, new Boolean(false), new Boolean(true),
new Boolean(false), new Boolean(false),
exchangeServer + "\n" + mailbox);
// print the current user for this Session.
AddressEntry user = new AddressEntryProxy(session.getCurrentUser());
System.out.println("Current user: " + user.getName());
// retrieve the inbox folder.
Integer folderType = new Integer(CdoDefaultFolderTypes.CdoDefaultFolderInbox);
Folder inbox = new FolderProxy(session.getDefaultFolder(folderType));
// get the message collection from the inbox.
Messages messages = new MessagesProxy(inbox.getMessages());
// get most recent message in the collection.
Message message = new MessageProxy(messages.getLast(null));
// print out message for confirmation.
String body = message.getText().toString();
String subject = message.getSubject().toString();
System.out.println("BODY:\n" + body +"\n");
// ***** The following demonstrates how to: *****
// ***** FORWARD A MESSAGE *****
// modify forwarding message details.
Message forwardMessage = new MessageProxy(message.forward());
String forwardMsg = "ENTER FORWARDING MESSAGE HERE";
forwardMessage.setSubject("FW: " + subject);
forwardMessage.setText(forwardMsg + "\n\n------- Original Message -------\n\n" + body);
// set message recipients.
Recipients recipients = new RecipientsProxy(forwardMessage.getRecipients());
Recipient r1 = new RecipientProxy(recipients.add(null, null, null, null));
Recipient r2 = new RecipientProxy(recipients.add(null, null, null, null));
// set recipients' addresses.
r1.setName("[email protected]");
r2.setName("[email protected]");
// r1 will be the 'to' address and r2 will be 'cc'-ied.
r1.setType(new Integer(CdoRecipientType.CdoTo));
r2.setType(new Integer(CdoRecipientType.CdoCc));
// Each recipient added must be resolved before it can be used.
// 0 == false to inhibit dialog boxes from popping up
r1.resolve(new Integer(0));
r2.resolve(new Integer(0));
// save changes to the message and send
forwardMessage.update(new Boolean(true), new Boolean(true));
forwardMessage.send(null, null, null);
// ***** The following demonstrates how to: *****
// ***** COPY A MESSAGE *****
// get destination folder's unique string ID
Integer newFolderType = new Integer(CdoDefaultFolderTypes.CdoDefaultFolderDeletedItems);
Folder deletedItems = new FolderProxy(session.getDefaultFolder(newFolderType));
String deletedItemsFolderID = deletedItems.getID().toString();
// copy message
Message copiedMessage = new MessageProxy(message.copyTo(deletedItemsFolderID, null));
copiedMessage.update(new Boolean(true), new Boolean(true));
// ***** The following demonstrates how to: *****
// ***** MOVE A MESSAGE *****
// move original message to the Deleted Items folder
message.moveTo(deletedItemsFolderID, null);
// log off from the session
session.logoff();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
// clean up and release all references
com.linar.jintegra.Cleaner.releaseAll();
}
}
} |
|