【Lotus Notes】邮件获取
public class LotusManager
{
public static int bodyMaxLength, length;
public static List<Entity.LotusMail> GetEmails(string psw,StringBuilder itemInfo,Action<OnGetEMail> onEMailGet) {
Domino.NotesSession ns = new Domino.NotesSession();
if (ns != null) {
try
{
ns.Initialize(psw);
}
catch {
throw new Exception("Lotus Notes密码错误!");
}
Domino.NotesDocumentCollection all = ns.GetDbDirectory("DominoT/TEST").OpenMailDatabase().AllDocuments;
Domino.NotesDocument nd = all.GetLastDocument();
List<Entity.LotusMail> mails = new List<Huawei.Yom.Lotus.Entity.LotusMail>();
//Entity.LotusMail mail;
//object[] items;
//Domino.NotesEmbeddedObject file;
//int count = 0;
while (nd != null)
{
#region 废弃代码
//mail = new Huawei.Yom.Lotus.Entity.LotusMail();
//mail.Subject = ((object[])nd.GetItemValue("Subject"))[0].ToString();
//mail.From = ((object[])nd.GetItemValue("From"))[0].ToString();
//mail.Body = ((object[])nd.GetItemValue("Body"))[0].ToString();
//mail.Date = ((object[])nd.GetItemValue("PostedDate"))[0].ToString();
//mail.Size = nd.Size.ToString();
//mail.NoteID = nd.NoteID;
//if (nd.Items == null)
//{
// continue;
//}
//items = (object[])nd.Items;
//if (items == null)
//{
// continue;
//}
//foreach (Domino.NotesItem item in items)
//{
// itemInfo.AppendFormat("#{0}#", item.Name);
// file = null; // if (item.Name == "$FILE")
// {
// try
// { // file = nd.GetAttachment(((object[])item.Values)[0].ToString()) as Domino.NotesEmbeddedObject;
// }
// catch
// { // }
// if (file != null)
// {
// if (mail.Attachments == null)
// {
// mail.Attachments = new List<Domino.NotesEmbeddedObject>();
// }
// mail.Attachments.Add(file); // }
// break;
// }
//}
//if (count++ >= 10)
//{
// break;
//}
#endregion
mails.Add(GetMailFromNotesDocument(nd));
if (onEMailGet != null) {
onEMailGet(new OnGetEMail()
{
count = all.Count,
currentIndex = mails.Count-,
email = mails[mails.Count - ]
});
}
nd = all.GetPrevDocument(nd);
}
return mails;
}
return null;
//Domino.NotesDocumentClass nddc = new Domino.NotesDocumentClass();
//return nddc.OpenMailDatabase().AllDocuments.Count;
} internal static Entity.LotusMail GetMailFromNotesDocument(Domino.NotesDocument nd)
{ Huawei.Yom.Lotus.Entity.LotusMail mail = new Huawei.Yom.Lotus.Entity.LotusMail();
mail.Subject = ((object[])nd.GetItemValue("Subject"))[].ToString();
mail.From = ((object[])nd.GetItemValue("From"))[].ToString();
mail.Body = ((object[])nd.GetItemValue("Body"))[].ToString();
//mail.Body = ((Domino.NotesItem)(((object[])nd.Items)[13])).Text;
//mail.Body = ((object[])nd.GetItemValue("wBody"))[0].ToString();
//mail.Date = ((object[])nd.GetItemValue("PostedDate"))[0].ToString();
//if (string.IsNullOrEmpty(mail.Date)) {
// //$Revisions
// mail.Date = ((object[])nd.GetItemValue("$Revisions"))[0].ToString();
//}
//mail.Date = nd.Created.ToString();
mail.Date = nd.LastModified.ToString();
mail.Size = nd.Size.ToString();
mail.NoteID = nd.NoteID;
object[] items = (object[])nd.Items;
bool isBodyGet=false,isDateGet=false;
//foreach (Domino.NotesItem item in items)
//{
// if (item.Name!="" && !string.IsNullOrEmpty(item.Text))
// {
// //mail.Body = item.Text;
// //break;
// }
//}
foreach (Domino.NotesItem item in items)
{
if (item.Name == "Body") {
mail.Body = item.Text;
//break;
isBodyGet=true;
}
if (item.Name == "DeliveredDate")
{
mail.Date = item.Text;
isDateGet = true;
}
if (isBodyGet && isDateGet) {
break;
}
}
//if (mail.Body.IndexOf("注意安全!!!目前广州、深圳常见的街头骗术!!") != -1)
//{
// mail.Body = ((Domino.NotesItem)(((object[])nd.Items)[13])).Text;
//foreach (Domino.NotesItem item in items)
//{
// if (item.Name == "Body" && !string.IsNullOrEmpty(item.Text))
// {
// //mail.Body = item.Text;
// //break;
// }
//}
//}
int bl = mail.Body.Length; if (bl > length)
{
int page = Convert.ToInt32(Math.Ceiling(bl * 1.0 / length));
bodyMaxLength = Math.Max(page, bodyMaxLength);
mail.WBody = new string[page];
for (int i = ; i < page; i++)
{
mail.WBody[i] = mail.Body.Substring(i * length, bl - i * length >= length ? length : bl - i * length);
}
}
else {
mail.WBody = new[] { mail.Body };
}
return mail;
} //public static int ByteLength(string str)
//{
// byte[] bytestr = System.Text.Encoding.Unicode.GetBytes(str);
// int j = 0;
// for (int i = 0; i < bytestr.GetLength(0); i++)
// {
// if (i % 2 == 0)
// { j++; }
// else
// {
// if (bytestr[i] > 0)
// { j++; }
// }
// }
// return j;
//}
}
public class LotusMail
{
public string NoteID
{
get;
set;
}
public string Subject
{
get;
set;
}
public string From
{
get;
set;
}
public string Date
{
get;
set;
}
public string Time
{
get;
set;
}
public string Size
{
get;
set;
}
public string Body
{
get;
set;
}
public List<Domino.NotesEmbeddedObject> Attachments
{
get;
set;
}
public string Other
{
get;
set;
}
public string[] WBody
{
get;
set;
上面是即时文件获取
下面是NSF文件里邮件获取
public class OnGetEMail {
public int count;
public int currentIndex;
public Entity.LotusMail email;
}
public class NsfDB
{
static Domino.NotesSession ns;
static Domino.NotesDatabase ndb;
public static void CreatSession(string psw) {
if (ns == null) {
ns = new Domino.NotesSession();
try
{
ns.Initialize(psw);
}
catch
{
throw new Exception("Lotus Notes密码错误!");
}
}
}
public static void Dispose(){
if (ns != null)
{
ns = null;
}
if (ndb != null)
{
ndb = null;
}
}
public static List<Entity.LotusMail> GetEmailData(string filename, string psw, Action<OnGetEMail> onEMailGet)
{
CreatSession(psw);
if (ns != null)
{
ndb = ns.GetDatabase(null, filename, false);
Domino.NotesDocumentCollection all =ndb.AllDocuments;
ndb = null;
Domino.NotesDocument nd = all.GetLastDocument();
List<Entity.LotusMail> mails = new List<Huawei.Yom.Lotus.Entity.LotusMail>();
while (nd != null)
{
try
{
mails.Add(LotusManager.GetMailFromNotesDocument(nd));
if (onEMailGet != null) {
onEMailGet(new OnGetEMail()
{
count = all.Count,
currentIndex = mails.Count-,
email = mails[mails.Count - ]
});
}
}
catch {
}
nd = all.GetPrevDocument(nd);
}
return mails;
}
return null;
}
public static object GetEmailDataTest(string filename,string psw)
{
Domino.NotesSession ns = new Domino.NotesSession();
if (ns != null)
{
ns.Initialize(psw);
NotesDatabase nd = ns.GetDatabase(null, filename, false);
return nd.AllDocuments.Count;
}
return null;
}
}
此例子需要引用两个COM组件:
- Lotus Domino Objects
- Lotus Notes Automation Classes
【Lotus Notes】邮件获取的更多相关文章
- C# Windows Service调用IBM Lotus Notes发送邮件
近日研究了下IBM Lotus Mail,这货果然是麻烦,由于公司策略,没有开放smtp,很多系统邮件都没有办法发送,于是入手google学习Lotus Mail,想做成Windows服务,提供wcf ...
- Lotus Notes中编程发送邮件(二)
在编程发送各种类似通知的邮件时,时常会需要发件人显示为某个特定的帐户,比如某个部门的名称或者管理员的名字.另一种需求是,用户收到某封邮件后,回复邮件的地址不同于发件人栏显示的地址.而正常情况下,发送邮 ...
- 46. Lotus Notes中编程发送邮件(一)
邮件是Lotus Notes体系的核心和基本功能,以至于Send()是NotesDocument的一个方法,任何一个文档都可以被发送出去,Notes里的一封邮件也只是一个有一些特殊字段的文档.在程序开 ...
- C# 使用 Lotus notes 公共邮箱发送邮件
公司的邮件系统用的是反人类的 Lotus notes, 你敢信? 最近要实现一个功能,邮件提醒功能,就是通过自动发送提醒邮件 前前后后这个问题搞了2天,由于公司的诸多条件限制,无法直接调用到公司发送邮 ...
- 我学到的新知识之——Lotus Notes闪退如何修复
很多企业内部都在使用IBM 出品的Lotus Notes 来收发邮件,以及内置的SameTime作为内部交流工具,作为用了多年微软套装产品的我来说,还是有些不适应. 最近遇到一个案例,只要用户登陆sa ...
- Lotus Notes 学习笔记
这是一个学习关于如何使用Lotus Notes的Agent功能来实现自动化办公的学习笔记. 一. 介绍 Lotus Notes/Domino 是一个世界领先的企业级通讯.协同工作及Internet/I ...
- 使用LotusScript操作Lotus Notes RTF域
Lotus Notes RTF域的功能也非常强大,除了支持普通的文本以外,还支持图片.表格.嵌入对象.Http 链接.Notes 链接.附件等等众多的类型.本文将介绍如何使用这些类来灵活操作富文本域. ...
- 55. 略谈Lotus Notes的与众不同及系列文章至此的总结
在二十多年的悠久历史里,Lotus Notes发展出一整套独特的概念.技术和思维.由于它早期惊人的领先时代和后续发展中同样惊人的忠于传统,这位软件领域的寿星在如今发展更新速度远超往日和技术愈趋公开互通 ...
- 52. 模版和设计元素——Lotus Notes的代码重用
不论是理论上还是实用上,代码重用都是编程的一个重要议题.可以从两个角度来讨论代码重用. 一是逻辑上代码以怎样的方式被重用.既可以通过面向对象的思想普及以来耳熟能详的继承的方式.比如先建了一个车的基类, ...
随机推荐
- Unity插件之NGUI学习(6)—— 关于Widget怎样加入触发事件(触发OnClick)
NGUI中,Button本身就带有OnClick事件,可是Sprite,Label等( 也绑有Widget的)并没有触发事件,事实上NGUI的事件触发都必须加入Box Collider,并勾选Is T ...
- passenger安装nginx
1.更换淘宝gem gem sources --remove https://rubygems.org/ gem sources -a https://ruby.taobao.org/ 2.gem安装 ...
- mysqldump报错
在使用mysqldump命令备份整个数据库的时候,报错例如以下: mysqldump: Couldn't execute 'SHOW TRIGGERS LIKE 'userlog'': Got err ...
- What is HHVM?
What is HHVM? HHVM is an open-source virtual machine designed for executing programs written in Hack ...
- EasyUI基础知识Draggable(拖累)
学习前easyui基于解析器,装载机.对他们来说,入门阶段,我们只需要在一个简单的理解.第一阶段,不宜过深后,.接着,根据easyui订购的文件正在研究安排官方网站Draggable插入. Dragg ...
- hdu 4869 Task(馋)
题目链接:hdu 4869 Task 题目大意:有n台机器,m个任务.每一个机器和任务都有有xi和yi.要求机器的xi.yi均大于等于任务的xi和yi才干运行任务. 每台机器一天仅仅能运行一个任务.要 ...
- C# 调用Webservice并传递序列化对象
原文:C# 调用Webservice并传递序列化对象 C#动态调用WebService注意要点 1.动态调用的url后面注意一定要加上?WSDL 例如:string _url = "ht ...
- css mainDiv和popbox居中
<style> .beCenter { width:460px; height:212px; background:#ccc; ...
- linux下C语言中的flock函数使用方法 .
表头文件 #include<sys/file.h> 定义函数 int flock(int fd,int operation); 函数说明 flock()会依參数operation所指 ...
- Goldeneye.py网站压力测试工具2.1版源码
Goldeneye压力测试工具的源代码,粗略看了下,代码写的蛮规范和易读的,打算边读边加上了中文注释,但是想来也没太大必要,代码600多行,值得学习的地方还是蛮多的,喜欢Python的同学可以一读 这 ...