首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 簡單操作 Lotus Notes 郵件(一):COM 參考、用戶列表獲取與發送郵件含附件

     編輯:關於C語言

前置準備:COM 參考

  • 加入參考 → COM → Lotus Domino Objects
  • 若找不到:regsvr32 "C:\Program Files\lotus\notes\nlsxbe.dll"
  • using Domino;

全域變數


NotesSession ns;
NotesDatabase ndb;

獲取用戶列表 (People View)


NotesView nv = ndb.GetView("($People)");
NotesDocument doc = nv.GetFirstDocument();
while (doc != null)
{
    string fullName = ((object[])doc.GetItemValue("FullName"))[0].ToString();
    cb_People.Items.Add(fullName);
    doc = nv.GetNextDocument(doc);
}

發送郵件含附件完整代碼


try
{
    if (ns != null)
    {
        NotesDocument doc = ndb.CreateDocument();
        doc.ReplaceItemValue("Form", "Memo");
        doc.ReplaceItemValue("SendTo", cb_People.Text);      // 收件人
        doc.ReplaceItemValue("Subject", tb_Subject.Text);    // 主旨
        
        // RichText 正文
        NotesRichTextItem rt = doc.CreateRichTextItem("Body");
        rt.AppendText(tb_Body.Text);
        
        // 附件
        if (!string.IsNullOrEmpty(tb_Attachment.Text))
        {
            NotesRichTextItem attachment = doc.CreateRichTextItem("attachment");
            attachment.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, "", tb_Attachment.Text, "attachment");
        }
        
        // 發送
        object obj = doc.GetItemValue("SendTo");
        doc.Send(false, ref obj);
        doc = null;
        MessageBox.Show("Successfully!");
    }
}
catch (Exception ex)
{
    MessageBox.Show("Error: " + ex.Message);
}

關鍵點總結

  • Form = "Memo":郵件表單類型
  • ReplaceItemValue:設定欄位值 (自動建立/覆蓋)
  • NotesRichTextItem:支援格式化文字與附件嵌入
  • EmbedObject(EMBED_ATTACHMENT, ...):嵌入檔案附件
  • Send(false, ref recipients):false = 不儲存至已發送箱
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved