必备条件:
1、本地有一个Lotus Notes的客户端,得到信息如下:
a:服务器的描述,例如:srvc7/srvc/cag
b:账号文件信息,例如:mail102/zhangsan1.nsf
c:密码, 例如:MyPassword
另外假设邮箱是:zhangsan1@mydomian.com
2、在启动VS时,添加引用,添加Com引用。由于你已经安装了Lotusnotes客户端,你可以在COM引用中看到Lotus Notes的引用,添加它,你的引用中会一个Domino的dll
3、在你的项目的命名空间中加上using Domino;
代码如下:
参数意义:
PSendTo:接受邮件地址
PCopyTo:抄送地址
PBlindCopyTo:暗送地址
PSubject:标题
PRemark:(这个参数我也不是太清楚)
PBody:正文
PAtt:附件
public static Boolean SendNotesMail(string PsendTo, string PcopyTo, string PBlindCopyTo, string PSubject, String PRemark, string PBody, string PAtt)
{
bool result;
try
{
NotesSession session = null;
session = new NotesSessionClass();
if (session == null)
{
return false;
}
try
{
NotesDatabase oNotesDatabase;
NotesDocument oNotesDocument;
string strNotesPassword = "MyPassword"; //密码(password used by COM to pass to the Notes client login)
string strNotesService = @"srvc7/srvc/cag"; //服务器的描述
string strNotesDataBase = @"mail102/zhangsan1.nsf"; //账号文件信息
session.Initialize(strNotesPassword); //Initialise session by passing a password. Lotus Notes will not load
oNotesDatabase = session.GetDatabase(strNotesService, strNotesDataBase, false); //create a database handle to the database you wish to send the mail message from.
if (!oNotesDatabase.IsOpen)
oNotesDatabase.Open();
oNotesDocument = oNotesDatabase.CreateDocument();
string[] arrPerson1 = PsendTo.Split(',');
oNotesDocument.AppendItemValue("SendTo", arrPerson1);
if (PcopyTo.Trim()!= "")
{
string[] arrPerson2 = PcopyTo.Split(',');
oNotesDocument.AppendItemValue("CopyTo", arrPerson2);
}
if (PBlindCopyTo.Trim()!= "")
{
string[] arrPerson3 = PBlindCopyTo.Split(',');
oNotesDocument.AppendItemValue("BlindCopyTo", arrPerson3);
}
oNotesDocument.AppendItemValue("Subject", PSubject);
oNotesDocument.ReplaceItemValue("Remark", PRemark);
oNotesDocument.AppendItemValue("From", "memo");
string psenddate = System.DateTime.Now.ToString("yyyy/MM/dd");
oNotesDocument.ReplaceItemValue("SendDate", psenddate);
session.ConvertMime = false;
Domino.NotesMIMEEntity bodyHtml = oNotesDocument.CreateMIMEEntity("Body");
Domino.NotesStream notesStream = session.CreateStream();
notesStream.WriteText(PBody, Domino.EOL_TYPE.EOL_NONE);
bodyHtml.SetContentFromText(notesStream, "text/html, charset=UIF-8", Domino.MIME_ENCODING.ENC_IDENTITY_BINARY);
notesStream.Truncate();
notesStream.Close();
oNotesDocument.CloseMIMEEntities(true, "Body");
session.ConvertMime = true;
oNotesDocument.ComputeWithForm(false, false);
NotesRichTextItem arrachment = oNotesDocument.CreateRichTextItem("attachment");
arrachment.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT,"", PAtt,"attachment");
object MailTo = arrPerson1;
oNotesDocument.Send(false, ref MailTo);
result = true;
}
catch(Exception ex)
{
return false;
}
finally
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(session);
}
}
catch(Exception ex)
{
result = false;
}
return result;
}