I am trying to read a particular email account to find items with attachments that are unread, and have certain words in the subject.
I have the below code that works but only reads my inbox and not the inbox I want to check
static void Main(string[] args)
{
ServicePointManager.ServerCertificateValidationCallback=CertificateValidationCallBack;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);// .Exchange2007_SP1);
service.UseDefaultCredentials = true;
service.AutodiscoverUrl("bbtest@domainname.com"); //, RedirectionUrlValidationCallback); //bbtest@bocuk.local
ItemView view = new ItemView(1);
string querystring = "HasAttachments:true Kind:email";
//From:'Philip Livingstone' Subject:'ATTACHMENT TEST' Kind:email";
// Find the first email message in the Inbox that has attachments.
// This results in a FindItem operation call to EWS.
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, querystring, view);
foreach (EmailMessage email in results)
if (email.IsRead == false) // && email.HasAttachments == true
{
System.Diagnostics.Debug.Write("Found attachemnt on msg with subject: " + email.Subject);
// Request all the attachments on the email message.
//This results in a GetItem operation call to EWS.
email.Load(new PropertySet(EmailMessageSchema.Attachments));
foreach (Attachment attachment in email.Attachments)
{
if (attachment is FileAttachment)
...
what do I have to change so that my code will read the messages in the inbox of bbtest@domainname.com?