Reputation: 1503
Can anyone provide an example of how to move selected inbox items to an external directory on the computer for example C:/Mails
I am not able to get the function to run after I have selected the mails into a folder on button click
I have tried the following code but i am not able to call this function on button click
internal static IEnumerable<MailItem> GetSelectedEmails()
{
foreach (MailItem email in new Microsoft.Office.Interop.Outlook.Application().ActiveExplorer().Selection)
{
yield return email;
}
}
onClick Code
private void MyButton_click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.GetSelectedEmails();
}
Thanks
Upvotes: 1
Views: 128
Reputation: 66265
The statement in that loop only execute when the next element of the returned collection is actually used (that's the point of yield). If the caller does not request an element, the code is not executed.
What does the calling code look like?
Change the code to the following - then the foreach loop will run:
internal static IEnumerable<MailItem> GetSelectedEmails()
{
var list = new List<MailItem>();
foreach (MailItem email in new Microsoft.Office.Interop.Outlook.Application().ActiveExplorer().Selection)
{
list.Add(email);
}
return list;
}
Upvotes: 0