How to redirect mailto links to Gmail compose window

I need help with customizing mailto link behavior in web browsers. When users click on email links like [email protected], I want the browser to open Gmail’s compose page instead of the default mail client. The Gmail composer should automatically populate the recipient field with the email address from the clicked link. Is there a way to configure this redirect functionality? I’ve tried different approaches but can’t get it working properly. The goal is to make sure that when someone clicks an email address on my website, it takes them directly to Gmail (assuming they’re signed in) with a new message window ready to send.

Just modify your mailto links to use Gmail’s compose URL instead. Replace the standard mailto syntax with https://mail.google.com/mail/?view=cm&[email protected] - swap in your actual email after to=. This skips the browser’s default mail client completely and opens Gmail directly with the recipient already filled in. I used this on my company site last year and it works great across all browsers. Only catch is users need to be logged into Google first, or they’ll hit the sign-in page before getting to compose.

There’s a browser-level fix that works way better. Modern browsers let you set Gmail as the default for mailto links. In Chrome: Settings > Privacy and Security > Site Settings > Additional permissions > Protocol handlers, then add Gmail. Firefox has the same thing under Preferences > General > Applications. After that, regular mailto links automatically open Gmail compose windows. Your HTML stays clean with standard mailto syntax, and the browser handles everything else. I’ve found this way more reliable than messing with URLs since it respects what users want and won’t break when Gmail changes their compose structure.

you can also use js to intercept mailto clicks and redirect them. this code works pretty well: document.querySelectorAll('a[href^="mailto:"]').forEach(link => link.addEventListener('click', function(e) { e.preventDefault(); window.open('https://mail.google.com/mail/?view=cm&to=' + this.href.substring(7)); })); not as clean as changing your browser settings, but gives you way more control.