by Andreas

OWA in an iFrame – yes, it’s possible

imageMicrosoft is very clear on one thing when it comes to showing OWA (Outlook Web App) in an iFrame: it is not supported, and you’re on your own (unless you’re using their Sharepoint web parts).

That doesn’t mean it can’t be done, and if you’re happy with the light version (no right-click support, no custom toolbar items and probably other missing features..) it can be done as easy as displaying the following HTML page in an iFrame:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>

<script>
    function LoginToOWA(server, domain, username, password) {


        var url = "https://" + server + "/owa/auth/owaauth.dll";
        // flags 0 = full version, flags 1 = light weight mode
        var p = { destination: 'https://' + server + '/exchange', flags: '1', forcedownlevel: '0', trusted: '0', isutf8: '1', username: domain + '\' + username, password: password };


        var myForm = document.createElement("form");
        myForm.method = "post";
        myForm.action = url;

        for (var k in p) {

            var myInput = document.createElement("input");
            myInput.setAttribute("name", k);
            myInput.setAttribute("value", p[k]);
            myForm.appendChild(myInput);
        }


        document.body.appendChild(myForm);
        myForm.submit();
        document.body.removeChild(myForm);
    }
</script>


<body onload="javascript:LoginToOWA('mail.someserver.com','yourdomain','yourusername@someserver.com','yourpassword');">
    <img src="../../gfx/loadingAnim.gif" /> Please wait while your inbox is loading...
</body>
</html>

 

The javascript function is called during the body onload event with the mail server url and logon credentials. That’s it, works like a charm!

Now, to make this work for the full version OWA and get the right click support and other features just make sure the web site is running on the same domain as your Exchange server. If your web site is hosted on somesite.someserver.com, and your Exchange is running on mail.someserver.com you should be good to go – despite some console warning messages that so far haven’t proven to cause any issues for me at least. The only change to the above code is to set the “flags” attribute to 0 instead of 1, and this switches from “light mode” to “full mode” (see in-code comment).

  • Peter

    Hi,

    I have tried this with Exchange Server 2013 and it is not working.
    If I open the html in the browser it works and opens owa but not in an iframe.
    And I think in the line:
    var p = { destination: ‘https://’ + server + ‘/exchange’, flags: ‘1’, forcedownlevel: ‘0’, trusted: ‘0’, isutf8: ‘1’, username: domain + ‘\’ + username, password: password };

    it should be ‘/owa’ insteed of ‘/exchange’ at least for Exchange 2013.

  • Pingback: Show OWA in iFrame | Technology & Programming()