Click here to Skip to main content
15,888,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

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


Thanks
Praveen
Posted
Updated 5-Jun-11 16:26pm
v2

In .NET you can serialise any object you want. But, how is .NET interacting with Outlook, and what do you mean by 'email object' ?
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900