Jak uzyskać treść wiadomości e-mail, potwierdzenie, nadawcę i informacje CC za pomocą EWS?

Czy ktoś może mi powiedzieć, jak uzyskać treść wiadomości e-mail, potwierdzenie, nadawcę, informacje CC za pomocą interfejsu API usługi internetowej Exchange? Wiem tylko, jak zdobyć przedmiot.

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
    service.Credentials = new NetworkCredential("user", "password", "domain");
    service.Url = new Uri("https://208.243.49.20/ews/exchange.asmx");
    ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
    FindItemsResults<Item> findResults = service.FindItems(
        WellKnownFolderName.Inbox,
        new ItemView(10));

    foreach (Item item in findResults.Items)
    {
        div_email.InnerHtml += item.Subject+"<br />";
    }

Moje środowisko programistyczne to asp.net C# Exchange-server 2010 Dziękuję.

Author: Daniel Hilgarth, 2011-07-12

4 answers

Użycie FindItems doprowadzi Cię tylko do tej pory, ponieważ zwraca tylko pierwsze 255 bajtów ciała. Co należy zrobić, to kombinacja FindItem, aby zażądać identyfikatorów wiadomości i wydać jedno lub więcej GetItem połączeń, aby uzyskać właściwości, które Cię interesują.

 10
Author: Henning Krause,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-02-28 16:17:51

Ponieważ pierwotne pytanie dotyczyło "treści wiadomości e-mail, paragonu, nadawcy i informacji o CC", pomyślałem, że się nimi zajmę. Zakładam ,że "Paragon" to informacje o odbiorcy, a nie Funkcja "powiadom nadawcę" wiadomości e-mail, której nikt nie używa. CC wygląda na to, że jest traktowany tak samo jak odbiorcy.

Podobała mi się odpowiedź Henninga, która zredukowała funkcję do dwóch wywołań, ale miałem trochę trudności z wymyśleniem, jak obsługiwać PropertySet. Wyszukiwanie w Google nie było od razu jasne w tej sprawie, i skończyło się na korzystanie z cudzego tutoriala :

// Simplified mail item
public class MailItem
{
    public string From;
    public string[] Recipients;
    public string Subject;
    public string Body;
}

public MailItem[] GetUnreadMailFromInbox()
{
    FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(128));
    ServiceResponseCollection<GetItemResponse> items = 
        service.BindToItems(findResults.Select(item => item.Id), new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.ToRecipients));
    return items.Select(item => {
        return new MailItem() {
            From = ((Microsoft.Exchange.WebServices.Data.EmailAddress)item.Item[EmailMessageSchema.From]).Address,
            Recipients = ((Microsoft.Exchange.WebServices.Data.EmailAddressCollection)item.Item[EmailMessageSchema.ToRecipients]).Select(recipient => recipient.Address).ToArray(),
            Subject = item.Item.Subject,
            Body = item.Item.Body.ToString(),
        };
    }).ToArray();
}
 32
Author: VeeTheSecond,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-14 18:08:57

Tutaj znajdziesz rozwiązanie.

Http://blogs.msdn.com/b/akashb/archive/2010/03/05/how-to-build-a-complex-search-using-searchfilter-and-searchfiltercollection-in-ews-managed-api-1-0.aspx


 // Send the request to search the Inbox and get the results.
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, FinalsearchFilter, view);



        // Process each item.
        if (findResults.Items.Count > 0)
        {
            foreach (Item myItem in findResults.Items)
            {
                if (myItem is EmailMessage)
                {
                    Console.WriteLine((myItem as EmailMessage).Subject);
                }
                if (myItem.ExtendedProperties.Count > 0)
                {
                    // Display the extended property's name and property.
                    foreach (ExtendedProperty extendedProperty in myItem.ExtendedProperties)
                    {
                        Console.WriteLine(" Extended Property Name: " + extendedProperty.PropertyDefinition.Name);
                        Console.WriteLine(" Extended Property Value: " + extendedProperty.Value);
                    }
                }

            }
        }
        else
        {
            Console.WriteLine("No Items Found!");
        }

    }
 2
Author: JAiro,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-07-12 19:46:57

Zamiast używać ExtendedProperties, możesz również wysłać wiadomość e-mail i bezpośrednio przeczytać właściwość, którą chcesz. Na przykład adres nadawcy:

((Microsoft.Exchange.WebServices.Data.EmailMessage)(item)).From.Address;
 2
Author: Johan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-04 13:17:10