Track Member activity and send communications

Is there a way to track:
1. How frequently members are logging in (i.e. Joe Smith was on the site 100 times in the last 30 days)?
2. The last time a member logged in?

Then, if there is a way to track those items, to send communications based on that information? So, for example, if someone hasn't logged in for >20 days, we want to send them an email that says "Is everything ok? We miss you! Here are some recent articles that have been posted that you might be interested in." Clearly, I'm not a copywriter, but hopefully that conveys what we want to accomplish.