Notes程式研究

本文介绍了一种使用C#在LotusNotes环境中发送电子邮件的方法。首先确保本地安装了LotusNotes客户端,并获取必要的配置信息如服务器描述、账号文件路径及密码。然后在Visual Studio项目中添加LotusDominoObjects引用,利用Domino.NotesSession对象进行邮件发送。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在SMTP伺服器,相應帳號已知的情況下,用C#發送電子郵件以有現成的函數,但對於使用Lotus Notes的網路中,如何發郵件,以下是一種方法供參考

1.保證本地有一個Lotus Notes 的用戶端,通過這個用戶端,你可以得到三個資訊,
1.伺服器的描述, 例如:srvc7/srvc/cag
2.帳號檔資訊 例如:mail102\zhangsan1.nsf
3.密碼 例如:MyPassword

<add key=”NotesDBServerStr” value=”CHNYT03/FOXCONN”/>

<add key=”NotesDBFilePathStr” value=”mail01\ytitsdt.nsf”/>

<add key=”NotesPassword” value=”84403736″/>

2. 在啟動VS2005專案,添加引用,添加COM引用,由於你已經安裝了lotus notes用戶端,你可以在COM引用中看到Lotus Notes的引用(Lotus Domino Objects),添加它,你得飲用中會多一個Domino的dll,
3.在你的項目的命名空間中,加上
using Domino;

4.以下是發送郵件的函數
public Boolean SendNotesMail(string ToMail, string Subject, string Body)
{
Domino.NotesSession oNotesSession = null; ;
Domino.NotesDatabase oNotesDatabase = null;
Domino.NotesDocument oNotesDocument = null;
object oItemValue = null;
//String sUserName;
String sPassword = “”; //Password used by COM to pass to the Notes client login.
String sServerName = “”;
String sMailFile = “”;

try
{
oNotesSession = new Domino.NotesSession(); //create a notes session object
//sPassword = MsgData.Password;
sPassword = “MyPassword”;
oNotesSession.Initialize(sPassword); //Initialise session by passing a password. Lotus Notes will not load.

//sUserName = oNotesSession.UserName;
//Console.WriteLine(sUserName);

//Create a database handle to the database you wish to send the mail message from.
//sServerName = MsgData.ServerName;
sServerName = @”srvc7/srvc/cag”;
//sMailFile = MsgData.MailFile;
sMailFile = @”mail102\zhangsan1.nsf”;
oNotesDatabase = oNotesSession.GetDatabase(sServerName, sMailFile, false);

//If the database is not already open then open it.
if (!oNotesDatabase.IsOpen)
{
oNotesDatabase.Open();
}
//Create an in memory document in the server database
oNotesDocument = oNotesDatabase.CreateDocument();
//Assign Field Values
oNotesDocument.ReplaceItemValue(“Form”, “Memo”);
//oNotesDocument.ReplaceItemValue(“From”, MsgData.FromMail);
oNotesDocument.ReplaceItemValue(“From”, zhangsan1@mydomain.com);
oNotesDocument.ReplaceItemValue(“SendTo”, ToMail);
oNotesDocument.ReplaceItemValue(“Subject”, Subject);
NotesRichTextItem rt = oNotesDocument.CreateRichTextItem(“Body”);
rt.AppendText(Body);
//oNotesDocument.ReplaceItemValue(“Body”, MsgData.Body);
oNotesDocument.SaveMessageOnSend = true; //Ensure memo shows in sent folder
oNotesDocument.ReplaceItemValue(“postDate”, DateTime.Now.ToShortDateString());

//Send requires an object for the recipients, so I give the send method the SendTo field as an object.

oItemValue = oNotesDocument.GetItemValue(“SendTo”);
//Send the email
oNotesDocument.Send(false, ref oItemValue);
return true;

}
catch (Exception error)
{
Console.WriteLine(“{0} My Exception caught.”, error);
return false;
}
finally
{
//if (oNotesSession != null) { Marshal.ReleaseComObject(oNotesSession); }
//if (oNotesDatabase != null) { Marshal.ReleaseComObject(oNotesDatabase); }
//if (oNotesDocument != null) { Marshal.ReleaseComObject(oNotesDocument); }
//if (oItemValue != null) { Marshal.ReleaseComObject(oItemValue); }

oNotesSession = null;
oNotesDatabase = null;
oNotesDocument = null;
oItemValue = null;
GC.Collect();
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值