How can iI transfer EWS get item body to PST file via golang or other language but C#

huangapple go评论77阅读模式
英文:

How can iI transfer EWS get item body to PST file via golang or other language but C#

问题

现在,我正在尝试导出电子邮件数据。导出的数据将被导入到 Outlook 中进行本地检查而不是服务器端。我已经阅读了文档链接描述在这里。我能否使用 Golang 或 cmd 工具将 EWS 数据(export-item/get-item)转移到 PST 文件中?谢谢!

英文:

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!

答案1

得分: 2

不直接在EWS中进行。您可以使用EWS导出MIME内容,然后使用自己的MIME解析器或内置的MIME转换器(仅限C++或Delphi,在outlook.exe进程内部调整时有效)或Redemption(任何语言,我是其作者,使用RDOMail.Import(..., olRfc822))将其导入到PST文件中。

但请注意,MIME不是高保真格式,所有特定于MAPI的属性都将丢失。快速传输流格式保留所有属性,但它没有文档。您可以使用"ExportItems" EWS请求导出项目,并使用Redemption和RDOMail.Import(..., olFTS)将其导入PST(或任何其他消息)中。可以使用RDOSession.LogonPstStore创建PST文件,然后可以创建文件夹(从RDOStore.RootIPMFolder开始使用RDOFolder.Folders.Add)和消息(RDOFolder.Items.Add)。

英文:

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).

答案2

得分: 2

我已经成功了。方法LogonPstStore的参数Encryption应该为0,这样Mac Outlook才能导入它。
Golang代码:

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
    }

    // 创建一个pst文件
    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
    }

    // 获取一个文件夹对象
    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
}
英文:

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

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

func main() {
ole.CoInitialize(0)
session, err := oleutil.CreateObject(&quot;Redemption.RDOSession&quot;)
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, &quot;LogonPstStore&quot;, p, 1, &quot;&quot;, &quot;&quot;, 0)
if err != nil {
fmt.Println(store, err)
return
}
// get a folder object
inbox, err := s.CallMethod(&quot;GetDefaultFolder&quot;, 6)
if err != nil {
fmt.Println(inbox, err)
return
}
stores := oleutil.MustGetProperty(s, &quot;Stores&quot;).ToIDispatch()
defaultStore := oleutil.MustGetProperty(stores, &quot;DefaultStore&quot;).ToIDispatch()
IPMRootFolder := oleutil.MustGetProperty(defaultStore, &quot;IPMRootFolder&quot;).ToIDispatch()
IPMFolders := oleutil.MustGetProperty(IPMRootFolder, &quot;Folders&quot;).ToIDispatch()
newFolder := oleutil.MustCallMethod(IPMFolders, &quot;Add&quot;, &quot;test22&quot;).ToIDispatch()
newFolderItems := oleutil.MustGetProperty(newFolder, &quot;Items&quot;).ToIDispatch()
RDOMail, err := newFolderItems.CallMethod(&quot;Add&quot;, &quot;IPM.Note&quot;)
if err != nil{
fmt.Println(RDOMail, err)
return
}
data := &quot;base64&quot;	 
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(&quot;Import&quot;, ftsDataPath, 1034)
if err != nil{
panic(err)
}
_, err = RDOMail.ToIDispatch().CallMethod(&quot;Save&quot;)
if err != nil{
panic(err)
}
_, err = defaultStore.CallMethod(&quot;Remove&quot;)
if err != nil{
panic(err)
}
v, err := s.GetProperty(&quot;FastShutdownSupported&quot;)
if err != nil{
fmt.Println(err)
}
if v.Value() != nil &amp;&amp; v.Value().(bool){
_, err = s.CallMethod(&quot;DoFastShutdown&quot;)
if err != nil{
fmt.Println(err)
}
}else {
_, err = s.CallMethod(&quot;Logoff&quot;)
if err != nil{
fmt.Println(err)
}
}
return
}

<!-- end snippet -->

huangapple
  • 本文由 发表于 2022年1月27日 11:09:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/70872858.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定