通过C#向Lotus Notes邮件添加附件

时间:2014-12-10 07:50:42

标签: c# email lotus

我找到了关于如何通过C#在本网站上发送Lotus Notes Mail的答案

    public void ComposeMemo(String sendto, String subject, String body)
    {
        // instantiate a Notes session and workspace
        Type NotesSession = Type.GetTypeFromProgID("Notes.NotesSession");
        Type NotesUIWorkspace = Type.GetTypeFromProgID("Notes.NotesUIWorkspace");
        Object sess = Activator.CreateInstance(NotesSession);
        Object ws = Activator.CreateInstance(NotesUIWorkspace);

        // open current user's mail file
        String mailServer = (String)NotesSession.InvokeMember("GetEnvironmentString", BindingFlags.InvokeMethod, null, sess, new Object[] { "MailServer", true });
        String mailFile = (String)NotesSession.InvokeMember("GetEnvironmentString", BindingFlags.InvokeMethod, null, sess, new Object[] { "MailFile", true });
        NotesUIWorkspace.InvokeMember("OpenDatabase", BindingFlags.InvokeMethod, null, ws, new Object[] { mailServer, mailFile });
        Object uidb = NotesUIWorkspace.InvokeMember("GetCurrentDatabase", BindingFlags.InvokeMethod, null, ws, null);
        Object db = NotesUIWorkspace.InvokeMember("Database", BindingFlags.GetProperty, null, uidb, null);
        Type NotesDatabase = db.GetType();

        // compose a new memo
        Object uidoc = NotesUIWorkspace.InvokeMember("ComposeDocument", BindingFlags.InvokeMethod, null, ws, new Object[] { mailServer, mailFile, "Memo", 0, 0, true });
        Type NotesUIDocument = uidoc.GetType();
        NotesUIDocument.InvokeMember("FieldSetText", BindingFlags.InvokeMethod, null, uidoc, new Object[] { "EnterSendTo", sendto });
        NotesUIDocument.InvokeMember("FieldSetText", BindingFlags.InvokeMethod, null, uidoc, new Object[] { "Subject", subject });
        NotesUIDocument.InvokeMember("FieldSetText", BindingFlags.InvokeMethod, null, uidoc, new Object[] { "Body", body });

        // bring the Notes window to the front
        String windowTitle = (String)NotesUIDocument.InvokeMember("WindowTitle", BindingFlags.GetProperty, null, uidoc, null);
        Interaction.AppActivate(windowTitle);
    }

如何向Lotus Notes邮件添加附件? 感谢您提供任何要求的信息。

我试过的这段代码就是工作! 只需添加五行。

    public void ComposeMemo(String sendto, String subject, String body)
    {
        // instantiate a Notes session and workspace
        Type NotesSession = Type.GetTypeFromProgID("Notes.NotesSession");
        Type NotesUIWorkspace = Type.GetTypeFromProgID("Notes.NotesUIWorkspace");
        Object sess = Activator.CreateInstance(NotesSession);
        Object ws = Activator.CreateInstance(NotesUIWorkspace);

        // open current user's mail file
        String mailServer = (String)NotesSession.InvokeMember("GetEnvironmentString", BindingFlags.InvokeMethod, null, sess, new Object[] { "MailServer", true });
        String mailFile = (String)NotesSession.InvokeMember("GetEnvironmentString", BindingFlags.InvokeMethod, null, sess, new Object[] { "MailFile", true });
        NotesUIWorkspace.InvokeMember("OpenDatabase", BindingFlags.InvokeMethod, null, ws, new Object[] { mailServer, mailFile });
        Object uidb = NotesUIWorkspace.InvokeMember("GetCurrentDatabase", BindingFlags.InvokeMethod, null, ws, null);
        Object db = NotesUIWorkspace.InvokeMember("Database", BindingFlags.GetProperty, null, uidb, null);
        Type NotesDatabase = db.GetType();

        // compose a new memo
        Object uidoc = NotesUIWorkspace.InvokeMember("ComposeDocument", BindingFlags.InvokeMethod, null, ws, new Object[] { mailServer, mailFile, "Memo", 0, 0, true });
        Type NotesUIDocument = uidoc.GetType();
        NotesUIDocument.InvokeMember("FieldSetText", BindingFlags.InvokeMethod, null, uidoc, new Object[] { "EnterSendTo", sendto });
        NotesUIDocument.InvokeMember("FieldSetText", BindingFlags.InvokeMethod, null, uidoc, new Object[] { "Subject", subject });
        NotesUIDocument.InvokeMember("FieldSetText", BindingFlags.InvokeMethod, null, uidoc, new Object[] { "Body", body });


        StringCollection paths = new StringCollection();
        paths.Add(@"C:\Users\Public\Pictures\Sample Pictures\IMG_1066.JPG");
        Clipboard.SetFileDropList(paths);

        NotesUIDocument.InvokeMember("GotoField", BindingFlags.InvokeMethod, null, uidoc, new Object[] { "Body" });
        NotesUIDocument.InvokeMember("Paste", BindingFlags.InvokeMethod, null, uidoc, null);



        // bring the Notes window to the front
        String windowTitle = (String)NotesUIDocument.InvokeMember("WindowTitle", BindingFlags.GetProperty, null, uidoc, null);
        Interaction.AppActivate(windowTitle);
    }

1 个答案:

答案 0 :(得分:0)

有一些信息here可能会对您有所帮助。

有添加附件到备忘录的指针,但似乎使用了同一个类(NotesUIDocument)。

[来自消息来源]

  

解决方法#1:将文件复制到剪贴板,然后使用   NotesUIDocument.Paste。不是我最喜欢的,因为它显然会破坏   用户在剪贴板上的任何内容,但这很容易做到。

     

解决方法#2:然后使用后端类创建电子邮件   使用NotesUIWorkspace.EditDocument方法将其显示给用户。   我注意到使用NotesRichTextItem提到的puru1981   NotesEmbeddedObject,但我发现使用richtext有点笨重。代替,   我正在使用较新的mime类(例如NotesMIMEEntity)。一世   没有任何使用OLE或C#的示例,但这是一个COM / VBA解决方案   你可以用来开始。

     

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/Lotus_SmartSuite/Lotus_Notes/Q_24468076.html#24575544

     

要记住以下几点:

     

1)我想不出你需要打电话的情况   CreatObject。这是一个应该保留的LotusScript / VB命令   从内部扩展客户端。

     

2)仅为NotesSession和NotesUIWorkspace调用CreateInstance。   这些是Notes土地中的根对象。 NotesSession用于后端   访问,用于GUI访问的NotesUIWorkspace。所有其他句柄应该是   从这些物品中的一个或其中的一个获得。