How to redirect user to application or appstore?

How I can navigate user to application if the application is already installed and if not then navigate to
appstore/google play?

I will be providing link into an email. so based on user’s platform like android or ios it should navigate user to either
to application or appstore

If there are any documentation or steps that will be great help.