protected override Task <List <MailMessage> > GetMessage(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            string account    = Account.Get(context);
            string filter     = Filter.Get(context);
            string folderpath = MailFolder.Get(context);
            int    top        = Top.Get(context);

            if (KnownFolder != 0)
            {
                KnownFolders result = KnownFolders.None;
                if (!Enum.TryParse(folderpath, ignoreCase: true, out result))
                {
                    folderpath = KnownFolder.ToString() + "\\" + folderpath;
                }
            }
            MAPIFolder         mAPIFolder   = GetFolder.GetFolders(folderpath, account);
            List <MailMessage> mailMessages = GetMessages.Messages(mAPIFolder, top, filter, OnlyUnreadMessages, MarkAsRead, true, TimeOrder, cancellationToken);

            return(StartNew(() => mailMessages));
        }
Beispiel #2
0
        private static string GetFromAddress(MailItem mailItem)
        {
            Application application = null;

            try
            {
                if (!(mailItem.SenderEmailType == "EX"))
                {
                    return(mailItem.SenderEmailAddress);
                }
                application = GetFolder.InitOutlook();
                Recipient    recipient    = application.GetNamespace("MAPI").CreateRecipient(mailItem.SenderEmailAddress);
                AddressEntry addressEntry = recipient.AddressEntry;
                if (addressEntry != null)
                {
                    if (addressEntry.AddressEntryUserType != 0 && addressEntry.AddressEntryUserType != OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
                    {
                        return(recipient.Address);
                    }
                    ExchangeUser exchangeUser = addressEntry.GetExchangeUser();
                    if (exchangeUser != null)
                    {
                        return(exchangeUser.PrimarySmtpAddress);
                    }
                }
            }
            catch (System.Exception ex)
            {
                Trace.TraceWarning(ex.ToString());
            }
            finally
            {
                if (application != null)
                {
                    Marshal.ReleaseComObject(application);
                }
            }
            return(string.Empty);
        }