【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的代码重用
不论是理论上还是实用上,代码重用都是编程的一个重要议题.可以从两个角度来讨论代码重用. 一是逻辑上代码以怎样的方式被重用.既可以通过面向对象的思想普及以来耳熟能详的继承的方式.比如先建了一个车的基类, ...
随机推荐
- elasticsearch的rest搜索--- 查询
目录: 一.针对这次装B 的解释 二.下载,安装插件elasticsearch-1.7.0 三.索引的mapping 四. 查询 五.对于相关度的大牛的文档 四. 查询 1. 查询的官网的文档 ...
- js调用wcf 的SOA
jquery 调用wcf 的SOA架构,将三层架构运用到SOA的架构中来 经过前面3天的学习,我想大家应该对SOA的架构有了初步的了解,其实 SOA与三层架构并不冲突,而是三层架构的升级版. 来看下传 ...
- 【百度地图API】如何在地图上添加标注?——另有:坐标拾取工具+打车费用接口介绍
原文:[百度地图API]如何在地图上添加标注?--另有:坐标拾取工具+打车费用接口介绍 摘要: 在这篇文章中,你将学会,如何利用百度地图API进行标注.如何使用API新增的打车费用接口. ------ ...
- 【百度地图API】除夕夜,大家一起来赶走“夕”——删除标注功能
原文:[百度地图API]除夕夜,大家一起来赶走"夕"--删除标注功能 任务描述: 农历12月31日是中国传统的节日——除夕.你知道除夕是怎么来的麼? “夕”在中国古代神话中,可是一 ...
- UVA The Sultan's Successors
题目例如以下: The Sultan's Successors The Sultan of Nubia has no children, so she has decided that thecou ...
- C语言学习-数据结构 - 倒插法顺序表
// test20161106.cpp : Defines the entry point for the console application. // #include "stdafx. ...
- unity多边形uv地图
我曾经写过一篇文章,不规则图形uv地图.(http://blog.csdn.net/itolfn/article/details/17240131)我用三角算法.但是,这种方法已经不完全,有一个指明: ...
- angular.js的路由和模板在asp.net mvc 中的使用
angular.js的路由和模板在asp.net mvc 中的使用 我们知道angular.js是基于mvc 的一款优秀js框架,它也有一套自己的路由机制,和asp.net mvc 路由不太一样.as ...
- HTML5它contenteditable属性
HTML5它contenteditable属性 1.功能说明 (1)功能:同意用户编辑元素中的内容 (2)说明:是一个布尔值.false是不能编辑,true为可编辑 2.分析实例 (1)content ...
- 我看PS求职简历照
看新闻<大学生求职简历照片不PS 连面试机会都没有>,忍不住也谈些自己的看法. 个人意见,尽量求真,这个求真要有平时努力的保证.长相一般的,知道自己是普通一员,按普通的方式行事就可以.即使 ...