I have a mailbox that receives an automated email every 5 mins from a remote station. contained within that email is a string that needs to be compared with the same string from the previous email.
I am trying to automate this process for obvious reasons.
So far i am able to read the ConversationTopic of the emails, however, i can't seem to figure out how to read the content of the emails.
when it call this:
email.Load();
MessageBox.Show(email.TextBody.Text.ToString());
i get the following error:
You must load or assign this property before you can read its value
I have had a google and i can't find anything that relates to my instance, so any help would be great.
This is my full code so far:
private void Form1_Load(object sender, EventArgs e)
{
try
{
//MessageBox.Show("Registering Exchange connection");
_service = new ExchangeService
{
Credentials = new WebCredentials("myaddy@domain.com", "*****")
};
}
catch
{
MessageBox.Show("new ExchangeService failed.");
return;
}
// This is the office365 webservice URL
_service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
// Prepare seperate class for writing email to the database
try
{
//MessageBox.Show("Reading mail");
// Read 100 mails
foreach (EmailMessage email in _service.FindItems(WellKnownFolderName.Inbox, new ItemView(10)))
{
if (email.ConversationTopic.ToString().Contains("from RockBLOCK 300234066454740"))
{
email.Load();
MessageBox.Show(email.TextBody.Text.ToString());
}
}
MessageBox.Show("Exiting");
}
catch (Exception ex)
{
MessageBox.Show("An error has occured. \n:" + ex.Message);
}
}