Q:

Get the email id based on user name in magento2

In the login page, I'm using the username instead of email.  Fetching the email is not working and shows the empty page.  Can please anyone help me.  
echo $username = $login['username']; 
                    $this->searchCriteriaBuilder->addFilter('r_user_dea', $username, 'like');                   

                    $searchCriteria = $this->searchCriteriaBuilder->create();
                    $list = $this->customerRepository->getList($searchCriteria);

                    if ($list->getTotalCount() > 0) {
                        foreach ($list->getItems() as $item) { 

                            echo $email = $item->getEmail(); exit; 
                            //$login['username'] = $email; 

                        }
                    }

$this->searchCriteriaBuilder->addFilter('r_user_dea', $username, 'like');

in this line, r_user_dea is my custom attribute.  

A:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
                $customerObj = $objectManager->create('Magento\Customer\Model\ResourceModel\Customer\Collection');
                $collection = $customerObj->addAttributeToSelect('*')
                              ->addAttributeToFilter('r_user_dea',$login['username'])
                              ->load();

               $cData=$collection->getData();

               $login['username'] = '';
                foreach($c_data as $data){
                     $email = $data['email'];
                }
                $login['username'] = $email;

