Q. How can I set the email address of all users with a blank email address to that of their UPN?

A. Using PowerShell its very easy to change the email address of every user with a blank email to that of their UPN:

$accounts=Get-ADUser -Filter * -Properties mail | where {$_.mail -eq $null} #| select sAMAccountName, UserPrincipalName, mail
foreach($account in $accounts)
    $account | Set-ADUser -EmailAddress $account.UserPrincipalName