C Check email existance in Outlook

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

// --------------------------------------------------------------------------------------------------------------------// <copyright file="EmailChecker.cs" company="Chimomo's Company">//   Respect the work.// </copyright>// <summary>//   Defines the EmailChecker type.// </summary>// --------------------------------------------------------------------------------------------------------------------namespace CSharpLearning{    using System;    using System.Linq;    using Microsoft.Exchange.WebServices.Data;    /// <summary>    /// The email checker class.    /// </summary>    internal class EmailChecker    {        /// <summary>        /// Check emails with the specified subject. Return the first mail item if found; null if not found.        /// </summary>        /// <param name="emailAddress">        /// The email address.        /// </param>        /// <param name="emailSubject">        /// The email subject.        /// </param>        /// <returns>        /// The <see cref="MailItem"/>.        /// </returns>        public static MailItem Check(string emailAddress, string emailSubject)        {            var exchangeService = new ExchangeService(ExchangeVersion.Exchange2010);            exchangeService.AutodiscoverUrl(emailAddress);            var findItemsResults = exchangeService.FindItems(WellKnownFolderName.Inbox, new ItemView(128));            var itemResponses = exchangeService.BindToItems(                    findItemsResults.Select(item => item.Id),                    new PropertySet(                        BasePropertySet.FirstClassProperties,                        EmailMessageSchema.From,                        EmailMessageSchema.ToRecipients,                        EmailMessageSchema.CcRecipients));            return itemResponses.Select(item => new MailItem            {                Time = item.Item.DateTimeReceived,                From = ((EmailAddress)item.Item[EmailMessageSchema.From]).Address,                Subject = item.Item.Subject,                To = ((EmailAddressCollection)item.Item[EmailMessageSchema.ToRecipients]).Select(recipient => recipient.Address).ToArray(),                CC = ((EmailAddressCollection)item.Item[EmailMessageSchema.CcRecipients]).Select(recipient => recipient.Address).ToArray(),                Body = item.Item.Body.ToString()            }).ToArray().FirstOrDefault(item => item.Subject == emailSubject);        }        /// <summary>        /// The mail item class.        /// </summary>        internal class MailItem        {            /// <summary>            /// Gets or sets the mail received time.            /// </summary>            public DateTime Time { get; set; }            /// <summary>            /// Gets or sets the mail from.            /// </summary>            public string From { get; set; }            /// <summary>            /// Gets or sets the mail subject.            /// </summary>            public string Subject { get; set; }            /// <summary>            /// Gets or sets the mail to.            /// </summary>            public string[] To { get; set; }            /// <summary>            /// Gets or sets the mail cc.            /// </summary>            public string[] CC { get; set; }            /// <summary>            /// Gets or sets the mail body.            /// </summary>            public string Body { get; set; }        }    }}
           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/yffhhffv/article/details/83820477