/**
*
*/
package de.tutorials;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* @author Tom
*
*/
public class OutlookControl {
public static int OUTLOOK_MAIL_ITEM = 0;
/**
* @param args
*/
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Outlook Automation");
shell.setLayout(new FillLayout());
OleFrame frm = new OleFrame(shell, SWT.NONE);
OleClientSite site = new OleClientSite(frm, SWT.NONE,
"Outlook.Application");
OleAutomation auto = new OleAutomation(site);
int[] GetNamespaceDispId = auto
.getIDsOfNames(new String[] { "GetNamespace" });
Variant Namespace = auto.invoke(GetNamespaceDispId[0],
new Variant[] { new Variant("MAPI") });
OleAutomation NamespaceAutomation = Namespace.getAutomation();
int[] LogonDispId = NamespaceAutomation
.getIDsOfNames(new String[] { "Logon" });
int[] LogoffDispId = NamespaceAutomation
.getIDsOfNames(new String[] { "Logoff" });
NamespaceAutomation.invoke(LogonDispId[0], new Variant[] {
new Variant("YOUR MAIL ACCOUNT"), new Variant("YOUR PASSWORD"),
new Variant(true), new Variant(true) });
int[] CreateItemDispId = auto
.getIDsOfNames(new String[] { "CreateItem" });
Variant mailItem = auto.invoke(CreateItemDispId[0],
new Variant[] { new Variant(OUTLOOK_MAIL_ITEM) });
OleAutomation mailItemAutomation = mailItem.getAutomation();
int[] ToPropertyDispId = mailItemAutomation
.getIDsOfNames(new String[] { "To" });
mailItemAutomation.setProperty(ToPropertyDispId[0], new Variant(
"YOUR RECIPIENT@SOMEDOMAIN.DE"));
int[] SubjectPropertyDispId = mailItemAutomation
.getIDsOfNames(new String[] { "Subject" });
mailItemAutomation
.setProperty(SubjectPropertyDispId[0], new Variant(
"SWT Outlook Automation Example "
+ System.currentTimeMillis()));
int[] BodyPropertyDispId = mailItemAutomation
.getIDsOfNames(new String[] { "Body" });
mailItemAutomation.setProperty(BodyPropertyDispId[0], new Variant(
"SWT OLE Automation Rockz! Powered by tutorials.de :)"));
int[] SendDispId = mailItemAutomation
.getIDsOfNames(new String[] { "Send" });
mailItemAutomation.invoke(SendDispId[0]);
NamespaceAutomation.invoke(LogoffDispId[0]);
shell.dispose();
auto.dispose();
NamespaceAutomation.dispose();
mailItemAutomation.dispose();
site.deactivateInPlaceClient();
site.dispose();
frm.dispose();
}
}