如何序列化Outlook电子邮件对象? [英] How to serialize outlook email object?

查看:68
本文介绍了如何序列化Outlook电子邮件对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我们有机会序列化Outlook电子邮件对象吗?
(因为Outlook邮件未序列化.)


谢谢
Praveen

Hi All,

Do we have any chance to serialize outlook email object?
(since, outlook mail is not serialized).


Thanks
Praveen

推荐答案

在.NET中,您可以序列化所需的任何对象.但是,.NET如何与Outlook交互,以及电子邮件对象"是什么意思?
In .NET you can serialise any object you want. But, how is .NET interacting with Outlook, and what do you mean by ''email object'' ?


public void ReadMails()
{
试试
{
app =新的Microsoft.Office.Interop.Outlook.Application();
ns = app.GetNamespace("MAPI");
ns.Logon(null,null,false,false);

inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

列表< OutlookMails> mailList = new List< OutlookMails>();
int errorCount = 0;
十进制垃圾= 0;
for(int i = 1; i< = inboxFolder.Items.Count; i ++)
{
试试
{
item =(Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items [i];

OutlookMails outLookMail =新的OutlookMails();
outLookMail.MailSubject = item.Subject;
outLookMail.Mail = item;
mailList.Add(outLookMail);
}
捕获(System.Exception ex)
{
errorCount ++;
}
}
}
捕获(例如System.Runtime.InteropServices.COMException)
{
Console.WriteLine(ex.ToString());
}
终于
{
ns = null;
app = null;
inboxFolder = null;
}
}


上面是我阅读Outlook电子邮件的示例代码,我将一次阅读一封Outlook电子邮件.
item =(Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items [i];
我们有一个API,可以将任何类型的值/对象(序列化)写入数据库.
现在,我的问题是我无法使用上述API将这个Outlook电子邮件对象写入数据库.


如果您有序列化Outlook电子邮件的解决方案,请提出建议.

-请不要建议我向API供应商寻求解决方案.
public void ReadMails()
{
try
{
app = new Microsoft.Office.Interop.Outlook.Application();
ns = app.GetNamespace("MAPI");
ns.Logon(null, null, false, false);

inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

List<OutlookMails> mailList = new List<OutlookMails>();
int errorCount = 0;
decimal garbage = 0;
for (int i = 1; i <= inboxFolder.Items.Count; i++)
{
try
{
item = (Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items[i];

OutlookMails outLookMail = new OutlookMails();
outLookMail.MailSubject = item.Subject;
outLookMail.Mail = item;
mailList.Add(outLookMail);
}
catch (System.Exception ex)
{
errorCount++;
}
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
ns = null;
app = null;
inboxFolder = null;
}
}


above is my sample code to read the outlook email, where I will be reading outlook email one at a time.
item = (Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items[i];
We have an API where which will write any type value/object(serialized) to database.
Now, my problem is I am not able to write this outlook email object to database using above API.


Please suggest me if you any solution to serialize outlook email.

-Please don''t suggest me to ask API venders for solution.


这篇关于如何序列化Outlook电子邮件对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆