Send email before role expiration
Create a custom module, implement hook_cron(), it is nothing but a function which will be called whenever cron runs.

Here is an article explaining what are hooks.

For code reference install examples module.


Implement hook_cron()
Load all the instance of the computed field, where you store the expiry date

Either you can directly query the database using db_select()
Or, use field_attach_load() to load only that field instances, instead of loading whole user object. Here is an example of how to use field_attach_load().

Check the expiry date.

Send a mail using drupal_mail() if the role is going to expire.



Note: You probably want this cron to run only once a day, for that install Elysia Cron and configure this hook to run once everyday by 12:00 am.