Outlook 2000: Aufgabe versenden mit SWT

rongricker

Grünschnabel
Hallo,
ich habe ein dringendes Problem:
Über meine Java-Applikation (mithilfe von SWT) sollen in Outlook Aufgaben erstellt UND versendet werden! Das erstellen und speichern der Aufgaben funktioniert, aber leider schaffe ich es nicht diese auch zu versenden :-( Alle Properties werden erfolgreich gespeichert, aber wenn ich mir die aus Java generierte Aufgabe in meinem Outlook Postfach anschaue, ist das "An:" -Feld immer leer und die Aufgabe wird nicht versendet.... Das Versenden einfacher Mails klappt übrigens.

Das Problem muss irgendwie beim setzen des Recipients-Properties liegen... im Beispiel unten versuche ich es mit einem Variant-Array... in anderen Versuchen mit einem einfachen Variant-Objekt funktionierte es auch nicht.

hier der Code:
Code:
public void swtTest() {
				
 		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" } );
 		NamespaceAutomation.invoke(LogonDispId[0], new Variant[] { new Variant( "XXX@XXX.de" ), 
 																   new Variant( "XXX" ),
 																   new Variant( true ), 
 																   new Variant( true ) });
 
 		
 		int[] createItemDispId = auto.getIDsOfNames( new String[] { "CreateItem" } );
 		Variant task = auto.invoke( createItemDispId[0], new Variant[] { new Variant( JConstant.OUTLOOK_TASK_ITEM ) } );
 		OleAutomation taskAutomation = task.getAutomation();
 		
 		int[] delegatorPropertyDispId = taskAutomation.getIDsOfNames( new String[] { "Delegator" } );
 		taskAutomation.setProperty( delegatorPropertyDispId[0], new Variant( "absender@test.de" ) );
 		
 		int[] subjectPropertyDispId = taskAutomation.getIDsOfNames( new String[] { "Subject" } );
 		taskAutomation.setProperty( subjectPropertyDispId[0], new Variant( "Dies ist der Betreff" ) );
 
 		int[] BodyPropertyDispId = taskAutomation.getIDsOfNames( new String[] { "Body" } );
 		taskAutomation.setProperty( BodyPropertyDispId[0], new Variant( "Hier steht der Inhalt der Aufgabe...") );
 		
 		int[] assignDispId = taskAutomation.getIDsOfNames( new String[] { "Assign" } );
 		taskAutomation.invoke( assignDispId[0] );
 		
 		int[] recipientsPropertyDispId = taskAutomation.getIDsOfNames( new String[] { "Recipients" } );
 		taskAutomation.setProperty( recipientsPropertyDispId[0], new Variant[]{ new Variant( "empfaenger@test.de" ) } );
 		
 		int[] saveDispId = taskAutomation.getIDsOfNames( new String[] { "Save" } );
 		taskAutomation.invoke( saveDispId[0] );
 		
 		int[] sendDispId = taskAutomation.getIDsOfNames( new String[] { "Send" } );
 		taskAutomation.invoke( sendDispId[0] );
 		
 		int[] LogoffDispId = NamespaceAutomation.getIDsOfNames( new String[] { "Logoff" } );
 		NamespaceAutomation.invoke( LogoffDispId[0] );
 		shell.dispose();
 		auto.dispose();
 		NamespaceAutomation.dispose();
 		taskAutomation.dispose();
 		site.deactivateInPlaceClient();
 		site.dispose();
 		frm.dispose();
 	}

hier die Office Outlook 2003 VBA Language Reference zum TaskItem Objekt:
http://msdn.microsoft.com/en-us/library/aa211067(office.11).aspx
ich nutze zwar Outlook 2000 aber das sollte nicht das Problem sein....

Ich bin für jeden Hinweis der mir irgendwie weiterhelfen könnte überaus dankbar.. ich verzweifle jetzt schon seit 2 Tagen an dem Problem :-(
 
So, jetzt sind wir schon zwei die nach einer Lösung suchen :) Aber wenigstens treibt sich hier im Forum ein Admin (Thomas Darimont) herum der sich mit Java und OLE Outlook auskennt.

Habe selbiges Problem, aber bisher noch keine Lösung gefunden. Möchte per Outlook eine Aufgabe versenden aber leider keinen Empfänger eintragen. Das Internet gibt leider nichts her. In anderen Programmiersprachen gibt es eine Art "Add" Befehl um die Empfänger einzufügen, ist aber mit Java wohl nicht ohne weiteres Möglich.

Hoffe wir kommen noch auf eine Lösung ohne andere Programmiersprache ;)
gruß Snu
 
Hallo Tom,
da ich Outlook 2010 benutze und bisher auch alles wie mit 2000 oder 2003 geklappt hat, wäre ich dir auch für eine 2003 Lösung dankbar ;) Ideal wär natürlich auch 2010 :)

Schonmal vielen Dank im vorraus, gruß Roman
 
Ich habe die Lösung auf unser Problem und es ist einfacher als man denkt :D Hab den Wald vor lauter Bäume nicht gesehn ...

Man legt sich einfach ne neue OleAutomation an mit den Recipients und invoked den Befehl "Add" mit einem String:

OleAutomation res = getProperty(task, "Recipients");
invoke(res, "Add", To);

Hier noch meine Methoden für das get/set/invoke (ist im Endeffekt genau wie deins, blos übersichtlicher gestaltet)

private static OleAutomation getProperty(OleAutomation auto, String name) {
Variant varResult = auto.getProperty(property(auto, name));
if (varResult != null && varResult.getType() != OLE.VT_EMPTY) {
OleAutomation result = varResult.getAutomation();
varResult.dispose();
return result;
}
return null;
}

private static Variant invoke(OleAutomation auto, String command, String value) {
return auto.invoke(property(auto, command), new Variant[]{new Variant(value)});
}

private static Variant invoke(OleAutomation auto, String command) {
return auto.invoke(property(auto, command));
}

private static Variant invoke(OleAutomation auto, String command, int value) {
return auto.invoke(property(auto, command), new Variant[]{new Variant(value)});
}

private static boolean setProperty(OleAutomation auto, String name, String value) {
return auto.setProperty(property(auto, name), new Variant(value));
}

private static boolean setProperty(OleAutomation auto, String name, int value) {
return auto.setProperty(property(auto, name), new Variant(value));
}

private static int property(OleAutomation auto, String name) {
return auto.getIDsOfNames(new String[]{name})[0];
}

Jetzt hab ich nur noch das Problem das mir die "Aufgabe" nicht in den Modus fürs Versenden an andere geht. Beim Task klappt das mit einem "Assign".

gruß Roman
 

Neue Beiträge

Zurück