So I have my public folders returning a count of the items within a specific public folder which works for me. These are saved as .msg which contain pure xml data.
I want to be able to read the xml data from the outlook.msg and store it in either temp table or memory so I can insert to sql server?
Here is what I have so far:
olApp = new Outlook.Application();
olNs = (Outlook._NameSpace) olApp.GetNamespace("MAPI");
oFolder = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
oExp = oFolder.GetExplorer(false);
olNs.Logon(Missing.Value, Missing.Value, false, true);
//pick a MAPI folder
Outlook.MAPIFolder publicFolders = (Outlook.MAPIFolder) olNs.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders).Folders["Food"];
try
{
foreach (Outlook.MAPIFolder f in publicFolders.Folders)
{
if (f.Name == "Burgers")
textBlockCount = f.Items.Count.ToString();
}
return;
}
catch (System.Exception e)
{
Log.Logging(e, "Mailbox exception");
}
This is a redacted xml file replacing any customer details with dummy data:
<?xml version="1.0"?>
<XMLCONTAINER version="1.0" incCount="3">
<APPLICATION id="APPLICATION_NODE_1" title="" name="55038170812101005FOODITEMS Foodpayment" application="Excel" appfile="%TURTLE%\xmlsForms\RDBxmls.xla" command="openRDBeDesigns">
<MAINDATA id="CONTAINER_NODE_2" title=""/>
<TURTLE.FORM id="CONTAINER_NODE_3" title="" table="tblMain" database="\\c\g\FDR1\FOODS\Data\Link\FOODpayments.mdb">
<FIELD fieldName="EID">1234567</FIELD>
<FIELD fieldName="DateTime">21/02/2019 14:50:17</FIELD>
<FIELD fieldName="DateOfLetter">21/02/19</FIELD>
<FIELD fieldName="Name">Mr Joe Blogs</FIELD>
<FIELD fieldName="CUSTID">RR123456R</FIELD>
<FIELD fieldName="paymentAmount">1144.80</FIELD>
<FIELD fieldName="AmountForPreviousYears">1144.80</FIELD>
<FIELD fieldName="NoPurple">i&e not comp'd - so he can't pay</FIELD>
<FIELD childID="CONTAINER_NODE_3_field59option1" fieldName="ComeBackReason">Sourcing2</FIELD>
<FIELD fieldName="Telephone">012345678</FIELD>
<FIELD fieldName="AcceptPhoneNumber">TRUE</FIELD>
<FIELD childID="CONTAINER_NODE_3_field7option4" fieldName="CustomerType">4</FIELD>
<FIELD fieldName="Target4">FALSE</FIELD>
<FIELD fieldName="Card">FALSE</FIELD>
<FIELD fieldName="ContractSettlement">FALSE</FIELD>
<FIELD fieldName="UPYear">512</FIELD>
<FIELD fieldName="AllocatedTo">1234567</FIELD>
<FIELD fieldName="LateCase">FALSE</FIELD>
</TURTLE.FORM>
</APPLICATION>
</XMLCONTAINER>
So I have been updating this and found out that PostItem works and MailItem doesn't. I am now able to show the message body, so how do I extract those FIELDS to a list or something? I put in the string mystring but does'nt look like it saves to it:
for (int i = 1; i < publicFolder.Items.Count; i++)
{
item = (PostItem)publicFolder.Items[i];
if (item != null)
{
MessageBox.Show(item.Subject, "Subject");
MessageBox.Show(item.BodyFormat.ToString(), "Item: {0}");
MessageBox.Show(item.Body, "Body");
string mystring = item.Body;
}
else
{
MessageBox.Show("No mail items found");
}
}