Created
August 9, 2016 05:51
-
-
Save whamtet/c538cb456cd951e1b382e02968b785fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def assembly-path "C:\\Users\\cplmam\\Downloads\\microsoft.office.interop.outlook.15.0.4797.1003\\lib\\net20\\Microsoft.Office.Interop.Outlook.dll") | |
(assembly-load-from assembly-path) | |
(import Microsoft.CSharp.CSharpCodeProvider) | |
(import System.CodeDom.Compiler.CompilerParameters) | |
(def provider (CSharpCodeProvider.)) | |
(def assemblies (into-array [assembly-path])) | |
(def compilerparams (CompilerParameters. assemblies)) | |
(.set_GenerateExecutable compilerparams false) | |
(.set_GenerateInMemory compilerparams true) | |
(defn cc [code] | |
(-> provider (.CompileAssemblyFromSource compilerparams code) .CompiledAssembly)) | |
(defn cm [code] | |
(-> code cc (.GetType "Hello1") (.GetMethod "Main"))) | |
(def m | |
(cm " | |
using System.Runtime.InteropServices; | |
using OutLook = Microsoft.Office.Interop.Outlook; | |
public class Hello1 | |
{ | |
public static object Main(OutLook.Application oApp) | |
{ | |
OutLook._NameSpace oNS = (OutLook._NameSpace)oApp.GetNamespace(\"MAPI\"); | |
OutLook.MAPIFolder oFolder = oNS.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderInbox); | |
OutLook.Items items = oFolder.Items; | |
foreach (OutLook.MailItem mail in items) | |
{ | |
return mail; | |
} | |
return null; | |
} | |
} | |
")) | |
(import System.Runtime.InteropServices.Marshal) | |
(defonce outlook (Marshal/GetActiveObject "Outlook.Application")) | |
(.Invoke m nil (to-array [outlook])) ;nil is an object for instance methods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment