github.com/go-ole/go-ole@v1.2.6/_example/outlook/outlook.go (about)

     1  // +build windows
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  
     8  	ole "github.com/go-ole/go-ole"
     9  	"github.com/go-ole/go-ole/oleutil"
    10  )
    11  
    12  func main() {
    13  	ole.CoInitialize(0)
    14  	unknown, _ := oleutil.CreateObject("Outlook.Application")
    15  	outlook, _ := unknown.QueryInterface(ole.IID_IDispatch)
    16  	ns := oleutil.MustCallMethod(outlook, "GetNamespace", "MAPI").ToIDispatch()
    17  	folder := oleutil.MustCallMethod(ns, "GetDefaultFolder", 10).ToIDispatch()
    18  	contacts := oleutil.MustCallMethod(folder, "Items").ToIDispatch()
    19  	count := oleutil.MustGetProperty(contacts, "Count").Value().(int32)
    20  	for i := 1; i <= int(count); i++ {
    21  		item, err := oleutil.GetProperty(contacts, "Item", i)
    22  		if err == nil && item.VT == ole.VT_DISPATCH {
    23  			if value, err := oleutil.GetProperty(item.ToIDispatch(), "FullName"); err == nil {
    24  				fmt.Println(value.Value())
    25  			}
    26  		}
    27  	}
    28  	oleutil.MustCallMethod(outlook, "Quit")
    29  }