Currently i have used exchange2010 to save the incoming email on my local drive with specified search criteria as soon as they arrive with the "connection.OnNotificationEvent" even and i have used "EventType.NewMail:" for new emails.
The new email whatever arrive saved successfully to my local drive into specific folder and now my requirement is to save the sent emails and i struggled a lot and could not find any event which will be fired as soon as any email sent from the mailbox.
Code as below to save incoming emails:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);//service1.Credentials = new NetworkCredential("{Active Directory ID}", "{Password}", "{Domain Name}");
service1.Credentials = new NetworkCredential(strUsername, strPassword, strDomain);
service1.AutodiscoverUrl(strAutodiscoverUrl);
//Mailbox mb = new Mailbox("artur.kedzior@ext.oami.europa.eu");
Mailbox mb = new Mailbox(strAutodiscoverUrl);
FolderId fid1 = new FolderId(WellKnownFolderName.Inbox, mb); foreach (NotificationEvent notification in args.Events)
{
switch (notification.EventType)
{
case EventType.NewMail:
foreach (EmailMessage message in service1.FindItems(fid1, searchFilter, new ItemView(int.MaxValue)))
{
if (message.ToRecipients.Count > 0)
{
strToRecepient = message.ToRecipients[0].Name;
}
message.Load(new PropertySet(ItemSchema.MimeContent));
MimeContent mc = message.MimeContent;
path = folderdrive + folderName + "\\" + strFileName;
FileStream fs = new FileStream(path, FileMode.Create);
fs.Write(mc.Content, 0, mc.Content.Length);
fs.Close();
}
}
break;
}
}
Please let me know what is the way to save sent email with EWS or any alternative aproach with sample code to do so.Thanks a million in advance.