skip to Main Content

how can i register the mailto: protocol handler for the Yahoo Mail web client?

I know the javascript to run should be smt like this:

navigator.registerProtocolHandler('mailto', 'https://compose.mail.yahoo.com/?%s', 'Yahoo Mail');

The problem is, their email composition URL domain compose.mail.yahoo.com is not the same as their main one mail.yahoo.com, so running registerProtocolHandler in the mail.yahoo.com inspector console gives the error:

Uncaught DOMException: Failed to execute ‘registerProtocolHandler’ on ‘Navigator’: Can only register custom handler in the document’s origin.
at :1:11

… and you can’t run it in a compose.mail.yahoo.com window because it immediately redirects away with an HTTP 302 to login.yahoo.com with an additional redirect (if you’re logged in) to mail.yahoo.com/d/compose.


So i can register such an handler? I just need to find a way to execute that javascript in the context of compose.mail.yahoo.com, i think..

2

Answers


  1. Chosen as BEST ANSWER

    I found an answer by myself, even though it's kind of an hack.

    1. log out of Yahoo! Mail
    2. go to the login page https://login.yahoo.com
    3. set the handler like this:
    navigator.registerProtocolHandler('mailto', 'https://login.yahoo.com?.src=ym&pspid=159600001&activity=mail-direct&.lang=en-US&.intl=us&.done=https%3A%2F%2Fcompose.mail.yahoo.com%2F%3Fto%3d%s', 'Yahoo Mail');
    

    That is a generic login link with a post-login redirect to the double-urlencoded URL present in the .done parameter, which translates to the compose.mail.yahoo.com link needed for yahoo mail.

    Adjust the &.lang=en-US&.intl=us as needed to set your preferred language.

    I don't know what the other parameters are for, exactly.

    I got this URL by checking what/how compose.mail.yahoo.com redirects to via curl:

    curl -L -i compose.mail.yahoo.com/[email protected]
    
    
    HTTP/1.1 301 Redirect
    Date: Fri, 17 Nov 2023 16:43:31 GMT
    Connection: keep-alive
    Server: ATS
    Cache-Control: no-store
    Location: https://compose.mail.yahoo.com/mrd/[email protected]
    Content-Type: text/html
    Content-Language: en
    Content-Length: 332
    
    HTTP/1.1 302 Found
    referrer-policy: origin-when-cross-origin
    strict-transport-security: max-age=31536000
    x-frame-options: DENY
    x-omg-env: norrin-green--istio-production-ir2-6cb7454cc6-qwvld
    location: https://login.yahoo.com?.src=ym&pspid=159600001&activity=mail-direct&.lang=en-US&.intl=us&.done=https%3A%2F%2Fcompose.mail.yahoo.com%2Fmrd%2Fmrd%2F%3Fto%3Dxxx%40xxx.com
    vary: Accept
    content-type: text/plain; charset=utf-8
    content-length: 190
    content-security-policy: script-src 'nonce-2dnbUx4mJ1RLHE1i43f1n+ZxjDBRnYSyNMmne9TtZ3DoZu/S'
    date: Fri, 17 Nov 2023 16:43:32 GMT
    x-envoy-upstream-service-time: 13
    server: ATS
    Age: 0
    Connection: keep-alive
    Expect-CT: max-age=31536000, report-uri="http://csp.yahoo.com/beacon/csp?src=yahoocom-expect-ct-report-only"
    X-XSS-Protection: 1; mode=block
    X-Content-Type-Options: nosniff
    

  2. Another possibility would be to setup a little redirect page on a website you possess, with a simple script like:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
    </head>
    
    <body>
        <script>
            const urlParams = new URLSearchParams(window.location.search)
            if (urlParams.has('s')) {
                // if parameter "s" present, create URL and navigate
                const s = urlParams.get('s')
                document.location.href = `https://compose.mail.yahoo.com/?to=${encodeURIComponent(s)}`
            } else {
                // else, allow the user to register the handler
                function register() {
                    const newHandler = `https://${document.location.host + document.location.pathname}?s=%s`
                    navigator.registerProtocolHandler('mailto', newHandler)
                }
            }
        </script>
    
        <button onclick="register()">register protocol handler for mailto: links</button>
        <a target="_blank"
            href="mailto:[email protected][email protected], [email protected], [email protected]&[email protected]&subject=Big%20News&body=Body+goes+here">Email
            test link</a>
    </body>
    
    </html>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search