Exemple #1
0
 private string GetRecipientListOfType(OlMailRecipientType recipientType)
 {
     return(Value
            .Recipients.Cast <Recipient>()
            .Where(recipient => recipient.Type == (int)recipientType)
            .Aggregate(string.Empty, (current, recipient) => current + (recipient.Address + ";")));
 }
 public RecipientInformationDto(string emailAddress, OlMailRecipientType recipientType)
 {
     this.fullName      = "";
     this.division      = "";
     this.companyName   = "";
     this.recipientType = recipientType;
     this.jobTitle      = "";
     this.emailAddress  = emailAddress;
 }
        /// <summary>
        /// メールのアドレスから宛先情報を検索する
        /// </summary>
        /// <param name="addressList">メールのTO, CC, BCC</param>
        /// <returns> 検索した宛先情報のリスト</returns>
        public List <RecipientInformationDto> SearchContact(List <Recipient> recipientsList, Utility.OutlookItemType itemType)
        {
            /// 検索結果の宛先情報のリスト
            List <RecipientInformationDto> _recipientInformationList = new List <RecipientInformationDto>();

            /// ファクトリオブジェクトに連絡先クラスのインスタンスの生成をしてもらう
            ContactFactory  contactFactory = new ContactFactory();
            List <IContact> contactList    = contactFactory.CreateContacts();

            /// ある1人の受信者の宛先情報を取得する
            foreach (var recipient in recipientsList)
            {
                RecipientInformationDto recipientInformation = null;

                try
                {
                    /// それぞれの連絡先クラスで検索する
                    foreach (var item in contactList)
                    {
                        ContactItem contactItem = item.getContactItem(recipient);

                        /// 送信先アドレスからその人の情報が見つかれば、名、部署、会社名、タイプをDtoにセット
                        if (contactItem != null)
                        {
                            string jobTitle = Utility.FormatJobTitle(contactItem.JobTitle);

                            // TaskRequstResponseは強制的にToにする
                            OlMailRecipientType recipientType = itemType != Utility.OutlookItemType.TaskRequestResponse ?
                                                                (OlMailRecipientType)recipient.Type :
                                                                OlMailRecipientType.olTo;

                            recipientInformation = new RecipientInformationDto(contactItem.FullName, contactItem.Department, contactItem.CompanyName, jobTitle, recipientType);
                            break;
                        }
                    }

                    if (recipientInformation == null)
                    {
                        recipientInformation = new RecipientInformationDto(
                            Utility.GetDisplayNameAndAddress(recipient),
                            (OlMailRecipientType)recipient.Type);
                    }
                    _recipientInformationList.Add(recipientInformation);
                }
                /// 例外が発生した場合、Nameを表示する
                catch (System.Exception ex)
                {
                    Console.WriteLine(ex.Message);

                    _recipientInformationList.Add(new RecipientInformationDto(
                                                      Utility.GetDisplayNameAndAddress(recipient),
                                                      (OlMailRecipientType)recipient.Type));
                }
            }

            return(_recipientInformationList);
        }
 public RecipientInformationDto(string fullName, string division,
                                string companyName, string jobTitle, OlMailRecipientType recipientType)
 {
     this.fullName      = fullName;
     this.division      = division;
     this.companyName   = companyName;
     this.recipientType = recipientType;
     this.jobTitle      = jobTitle;
     this.emailAddress  = "";
 }
Exemple #5
0
        private void ResloveReceipents(IEnumerable <string> recipients, OlMailRecipientType mailRecipientType)
        {
            Recipients oRecips = outlookMsg.Recipients;

            foreach (var recipient in recipients)
            {
                Recipient ccRecipient = oRecips.Add(recipient);
                ccRecipient.Type = (int)mailRecipientType;
                ccRecipient.Resolve();
            }
        }
        private static string[] convertRecipientList(Recipients recipients, OlMailRecipientType type)
        {
            if (recipients == null)
            {
                return(null);
            }

            List <String> emails = new List <String>();

            for (int i = 1; i < recipients.Count + 1; i++)
            {
                if (recipients[i].Type == (int)type)
                {
                    emails.Add(recipients[i].Address);
                }
            }

            if (emails.Count == 0)
            {
                return(null);
            }

            return(emails.ToArray() as string[]);
        }
        public static MailAddressCollection GetMailAddressCollection(MailItem mailItem, OlMailRecipientType recipentType)
        {
            MailAddressCollection mailAddressCollection = new MailAddressCollection();
            Recipients            recipients            = mailItem.Recipients;

            try
            {
                foreach (Recipient item in recipients)
                {
                    if (item.Type == (int)recipentType)
                    {
                        try
                        {
                            string text = item.Address;
                            if (!text.Contains("@"))
                            {
                                try
                                {
                                    text = ((dynamic)item.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E")).ToString();
                                }
                                catch (System.Exception ex)
                                {
                                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个异常产生", ex.Message);
                                }
                            }
                            mailAddressCollection.Add(new MailAddress(text, item.Name));
                        }
                        catch (System.Exception ex)
                        {
                            SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个异常产生", ex.Message);
                        }
                    }
                }
                return(mailAddressCollection);
            }
            finally
            {
                if (recipients != null)
                {
                    Marshal.ReleaseComObject(recipients);
                }
            }
        }
		private void AddRecipient(IWSRecipients recipients, OlMailRecipientType recipientType, string emailAddress)
		{
			using (IWSRecipient recipient = recipients.Add(emailAddress))
			{
				recipient.Type = (int) recipientType;
				recipient.Resolve(false);
			}
		}
		private IWSRecipient FindRecipient(IEnumerable<IWSRecipient> recipients, OlMailRecipientType recipientType, string displayName)
		{
			foreach (IWSRecipient recipient in recipients)
			{
				if (recipient.Name == displayName && recipient.Type == (int) recipientType)
				{
					return recipient;
				}
				recipient.Dispose();
			}

			return null;
		}
		private void AddRecipientOOM(MailItem mailItem, OlMailRecipientType recipientType, string emailAddress)
		{
			Recipient recipient = mailItem.Recipients.Add(emailAddress);
			recipient.Type = (int) recipientType;
			recipient.Resolve();
		}
		private Recipient FindRecipientOOM(MailItem mailItem, OlMailRecipientType recipientType, string displayName)
		{
			foreach (Recipient recipient in mailItem.Recipients)
			{
                try
                {
				    if (recipient.Name == displayName && recipient.Type == (int) recipientType)
				    {
					    return recipient;
				    }
                }
                finally
                {
                    if (Marshal.IsComObject(recipient))
                    {
				        Marshal.ReleaseComObject(recipient);
                    }
                }
			}

			return null;
		}