コード例 #1
0
        private void FillMailCopyRecipients()
        {
            //Добавление адресатов
            List <ReferenceObject> tempUsers = new List <ReferenceObject>();

            foreach (IMailRecipient recipient in MailCopyRecipients)
            {
                if (recipient.UserReferenceObject != null)
                {
                    UserReferenceObject recipient_uro = recipient.UserReferenceObject as UserReferenceObject;
                    if (recipient_uro is User)
                    {
                        tempUsers.Add(recipient_uro);
                    }
                    else if (recipient_uro is UsersGroup)
                    {
                        List <User> internUsers = recipient_uro.GetAllInternalUsers();
                        if (internUsers != null)
                        {
                            tempUsers.AddRange(recipient_uro.GetAllInternalUsers());
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                else if (!string.IsNullOrWhiteSpace(recipient.Email))
                {
                    MailMessage.To.Add(new EMailAddress(recipient.Email));
                }
                else
                {
                    throw new Exception("Отсутствуют данные адресата для отправки письма!");
                }
            }
            List <ReferenceObject> users = new List <ReferenceObject>();

            foreach (var item in tempUsers)
            {
                users.Add(item);
                users.AddRange(item.Children);
            }
            if (users.Distinct() == null)
            {
                return;
            }

            foreach (UserReferenceObject user in users.Distinct())
            {
                User mailuser = user as User;
                MailMessage.Copy.Add(new MailUser(mailuser));

                if (mailuser.Email != null && !mailuser.Email.IsEmpty)
                {
                    MailMessage.Copy.Add(new EMailAddress(mailuser.Email.ToString()));
                }
            }
        }
コード例 #2
0
        private void FillMailCopyRecipients()
        {
            //Добавление адресатов
            List <ReferenceObject> tempUsers = new List <ReferenceObject>();

            foreach (ReferenceObject recipient_ro in MailCopyRecipients)
            {
                UserReferenceObject recipient_uro = recipient_ro as UserReferenceObject;
                if (recipient_uro is User)
                {
                    tempUsers.Add(recipient_ro);
                }
                else if (recipient_uro is UsersGroup)
                {
                    List <User> internUsers = recipient_uro.GetAllInternalUsers();
                    if (internUsers != null)
                    {
                        tempUsers.AddRange(recipient_uro.GetAllInternalUsers());
                    }
                }
                else
                {
                    continue;
                }
            }
            List <ReferenceObject> users = new List <ReferenceObject>();

            foreach (var item in tempUsers)
            {
                users.Add(item);
                users.AddRange(item.Children);
            }
            if (users.Distinct() == null)
            {
                return;
            }

            foreach (UserReferenceObject user in users.Distinct())
            {
                User mailuser = user as User;
                MailMessage.Copy.Add(new MailUser(mailuser));

                if (mailuser.Email != null && !mailuser.Email.IsEmpty)
                {
                    MailMessage.Copy.Add(new EMailAddress(mailuser.Email.ToString()));
                }
            }
        }