You should use the Microsoft Graph API for this, which could be used in native apps and web applications. There are several examples available on connecting to the Microsoft Graph.
The API reference could be found here: http://graph.microsoft.io
Or try the Graph Explorer to try the API: https://graphexplorer2.azurewebsites.net
To retrieve users with assigned licenses:
First get the subscribed Skus from your tenant using:
https://graph.windows.net/rbd3v.onmicrosoft.com/subscribedSkus
(Where rbd3v.onmicrosoft.com should be replaced with your tenant)
Next you could retrieve all users with the assigned licenses:
https://graph.windows.net/rbd3v.onmicrosoft.com/users
Which will return something like this:
The SkuId of ‘assignedlicenses’ will match a license retrieved from the first request.
Get list of mail boxes
The same way you could retrieve all the mailboxes.
By retrieving all the users and groups in your tenant and extract their email address.
For an overview of available requests check:
https://msdn.microsoft.com/Library/Azure/Ad/Graph/api/api-catalog
Hope this will help you!