Create A Custom Email Address for External Office 365 Users

With SharePoint Online, you can create sites that external users can log into and access. This is great for things like sharing documents, with a lot more functionality than a plain file download and upload like Dropbox.

Unfortunately, there isn’t an easy way to create a manual user, but have notifications go to their external email address. When you create a user in Office 365 or Azure AD, they have to be set up with one of your valid, owned domains.

There is a way to modify the ‘Work Email’ field of a cloud user, which is then used by SharePoint Online to send notifications and updates to whatever address they want – but at the time of writing this, can’t be done via the webpage GUI, nor by native PowerShell commands.

There is a way though, thanks to a script written by Ivan Yankulov called “Script to Write and Get User Profile Properties in SharePoint Online with CSOM

The script uses the API’s of SharePoint Online to make changes to users, but read Ivan’s explanation of it on his blog if you’re interested in understanding how it works.

 

These instructions assume you’ve already created the user in Office 365/Azure AD.

Log on to SharePoint Online as user: http://yourwebsite.sharepoint.com

Install SharePoint Online Client Components SDK

Download script Script to Write and Get User Profile Properties in SharePoint Online with CSOM

To get user’s details (need to be an Office 365 Global admin, and use standard PowerShell to launch the .ps1 file from the script above):

.\Get-SPOUserProfileProperty.ps1 -accountname “user@yourdomain.onmicrosoft.com” -spoadminportalurl “https://yourdomain-admin.sharepoint.com” -username youradminaccount@onmicrosoft.com – password xxx

If you don’t specify the password in the command line, it will prompt for credentials (which is fine). This will make sure things are working, and you’ll see all the fields of that user

To set user’s details:

.\set-SPOUserProfileProperty.ps1 -propertyname WorkEmail -accountname “user@yourdomain.onmicrosoft.com” -value personalemail@customdomain.com -spoadminportalurl “https://yourdomain-admin.sharepoint.com” -username youradminaccount@onmicrosoft.com -password xxx

This is fine on a single user basis, but can also be scripted:

$data = import-csv -path C:\Temp\userdetails.csv
foreach ($user in $data){
.\set-SPOUserProfileProperty.ps1 -propertyname WorkEmail -accountname $user.UserPrincipalName -value $user.EmailAddress -spoadminportalurl “https://yourdomain-admin.sharepoint.com” -username youradminaccount@onmicrosoft.com -password xxx
}

The password is specified in this script because you’ll be prompted for the password on every single user change. You can always save this script, add your password, run the script but not save the changes.

The CSV file used is the same as my last article Office 365 and PowerShell Cloud User Creation

DisplayName,FirstName,LastName,Password,EmailAddress,UserPrincipalName
Richard Sole,Richard,Sole,ILovePSv4,r.sole@contoso.com,r.sole@mydomain.onmicrosoft.com

If you have any issues getting the above working, feel free to ask in the comments below.

Leave a Reply