how can i transfer ews get item body to pst file via golang or other language but c#

Issue

now,i am trying to export email data. The data exported will be import to outlook to check locally but server.
i have read the doc enter link description here.
Can i transfer ews data (export-item/get-item) to pst file using golang or cmd tools?
Thank you!

Solution

I have success.The method LogonPstStore params Encryption should be 0 so that mac outlook can import it.
Golang code:

func main() {
    ole.CoInitialize(0)
    session, err := oleutil.CreateObject("Redemption.RDOSession")
    if err != nil {
        fmt.Println(err)
        return
    }

    s, err := session.QueryInterface(ole.IID_IDispatch)
    if err != nil {
        fmt.Println(err)
        return
    }

    // create a pst file
    p := `E:\go_project\src\github.com\outlook-ical-export\redemption\t22.pst`
    store, err := oleutil.CallMethod(s, "LogonPstStore", p, 1, "", "", 0)
    if err != nil {
        fmt.Println(store, err)
        return
    }

    // get a folder object
    inbox, err := s.CallMethod("GetDefaultFolder", 6)
    if err != nil {
        fmt.Println(inbox, err)
        return
    }

    stores := oleutil.MustGetProperty(s, "Stores").ToIDispatch()

    defaultStore := oleutil.MustGetProperty(stores, "DefaultStore").ToIDispatch()
    IPMRootFolder := oleutil.MustGetProperty(defaultStore, "IPMRootFolder").ToIDispatch()
    IPMFolders := oleutil.MustGetProperty(IPMRootFolder, "Folders").ToIDispatch()

    newFolder := oleutil.MustCallMethod(IPMFolders, "Add", "test22").ToIDispatch()
    newFolderItems := oleutil.MustGetProperty(newFolder, "Items").ToIDispatch()
    RDOMail, err := newFolderItems.CallMethod("Add", "IPM.Note")
    if err != nil{
        fmt.Println(RDOMail, err)
        return
    }

  data := "base64"   
    ftsDataPath:= `E:\go_project\src\github.com\outlook-ical-export\redemption\test22.txt`

    d, err := base64.StdEncoding.DecodeString(data)

    err = ioutil.WriteFile(ftsDataPath, d, 0644)
    if err != nil {
        panic(err)
    }

    _, err = RDOMail.ToIDispatch().CallMethod("Import", ftsDataPath, 1034)
    if err != nil{
        panic(err)
    }

    _, err = RDOMail.ToIDispatch().CallMethod("Save")
    if err != nil{
        panic(err)
    }

    _, err = defaultStore.CallMethod("Remove")
    if err != nil{
        panic(err)
    }

    v, err := s.GetProperty("FastShutdownSupported")
    if err != nil{
        fmt.Println(err)
    }

    if v.Value() != nil && v.Value().(bool){
        _, err = s.CallMethod("DoFastShutdown")
        if err != nil{
            fmt.Println(err)
        }
    }else {
        _, err = s.CallMethod("Logoff")
        if err != nil{
            fmt.Println(err)
        }
    }

    return
}

Answered By – catFly

Answer Checked By – Clifford M. (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.