Reputation: 81
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!
Upvotes: 2
Views: 641
Reputation: 66276
Not in EWS directly. You can export the MIME content using EWS and then import it into a PST file either using your own MIME parser, IConverterSession built-in MIME converter (C++ or Delphi only, only works when tuning inside the outlook.exe process) or Redemption (any language, I am its author, use RDOMail.Import(..., olRfc822)
).
Note however that MIME is not a high fidelity format, all MAPI-specific properties will be lost. Fast Transfer Stream format preserves all properties, but it is not documented. You can export the items using the ExportItems
EWS request, and import them into a PST (or any other message) using Redemption and RDOMail.Import(..., olFTS)
. A PST file can be created using RDOSession.LogonPstStore
, you can then create folders (RDOFolder.Folders.Add
starting with RDOStore.RootIPMFolder
) and messages (RDOFolder.Items.Add
).
Upvotes: 2
Reputation: 81
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
}
Upvotes: 2