The implementation of this is specific to your program and will have to make it.
But to retrieve the number of new messages since the last login you can use a query which would look something like
SELECT COUNT(*) FROM <email table> WHERE DATEDIFF(minute,<datereceived>,<datelastlogon>) > 0
This supposes that you both store the last login time for a user and the time a message is received.