【问题标题】:Add attachments to Lotus Notes mail by C#使用 C# 将附件添加到 Lotus Notes 邮件
【发布时间】:2014-12-10 07:50:41
【问题描述】:

我在这个网站上找到了有关如何通过 C# 发送 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 });

        // 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);
    }

【问题讨论】:

    标签: c# email lotus


    【解决方案1】:

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

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

    [来源]

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

    解决方法 #2:仅使用后端类创建电子邮件,然后 使用 NotesUIWorkspace.EditDocument 方法将其显示给用户。 我注意到 puru1981 提到使用 NotesRichTextItem 和 NotesEmbeddedObject,但我发现使用富文本有点笨拙。反而, 我正在使用较新的 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) 我想不出你需要打电话的情况 创建对象。那是一个应该保留的 LotusScript/VB 命令 用于从内部扩展客户端。

    2) 仅为 NotesSession 和 NotesUIWorkspace 调用 CreateInstance。 这些是 Notes 领域中的根对象。后端的 NotesSession 访问,用于 GUI 访问的 NotesUIWorkspace。所有其他手柄应该是 从这些对象之一或其子对象中获得。

    【讨论】:

    • 我看不到答案。能否请您复制并张贴在这里?
    • 非常感谢您的帮助,非常感谢。
    • 如果我的回答帮助你达到了你的成绩,请将其标记为回答,这样我可以获得一些积分奖励。谢谢!
    • 你的回答很好。但是您能否添加可以实现邮件附件的代码? Plz~~ 我认为它是这样的: NotesUIDocument.InvokeMember("FieldSetText", BindingFlags.InvokeMethod, null, uidoc, new Object[] { "Subject", "Subject" });
    • 好的。首先,将文件复制到剪贴板,这里是一个例子:stackoverflow.com/questions/211611/…
    猜你喜欢
    • 2015-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多