前置準備: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 = 不儲存至已發送箱