Aurora documentation

Embedding WebMail into your web application via IFRAME

Introduction

You may need to make Aurora interface a part of your web site interface. For example, if your web site has several sections (e.g. "My Blog", "My Pictures", "My Mail") and a navigation menu which should always stay on the screen (no matter which section is currently selected), webmail interface shouldn't overlap the navigation menu and shouldn't be opened in a separate window.

To achieve this, you need to place Aurora interface into an IFRAME which is a part of your interface. Placing it directly into your interface (e.g. into a DIV element) is not possible as it's complex AJAX application which relies to absolute coordinates and has its own system of exchanging data packets with server. So, an IFRAME is the only way to get it working properly.

Note that it's possible to disallow placing Aurora interface into IFRAME, see Preventing clickjacking attacks with X-Frame-Options header documentation page for details.

Simple embedding into your interface

The following example demonstrates how to place Aurora interface into an IFRAME:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
<html>
    <head>
        <title>iframe test</title>
    </head>
    <body>
        <div style="background-color: #EEE; width: 1000px;">Your navigation menu here</div><br />
        <iframe src="http://webmail.afterlogic.com/" style="width: 1000px; height: 640px;"></iframe>
    </body>
</html>

Here, you can see http://webmail.afterlogic.com/ URL mentioned. It points to AfterLogic WebMail Pro PHP live demo at our web site. You should change this URL to the one pointing to your product installation.

Note that in version 7, IFRAME height and width should be 640px at least, to avoid getting scrollbars.

Embedding into your interface along with passing authentication data

Now let's use visual integration along with passing authentication data to Aurora which is described here. First, please create test-iframe.php file and copy/paste the code from Basic example section there, then modify the example to get it working in your environment. It's assumed that you placed that file into the integration subdirectory of your Aurora installation (which, in turn, is found in webmail subdirectory of your website). The code will be slightly modified (see below).

Now, just add the following line to one of your PHP pages:

<iframe src="webmail/integration/test-iframe.php" style="width: 1000px; height: 640px;"></iframe>

Now, you may wonder how to pass authentication data from your PHP application to LoginToAccount method called in test-iframe.php. We won't pass those data through POST method, server-side PHP sessions are used instead. Example:

* index.php file:

<?php

session_start();

// Store credentials in session
$_SESSION['email'] = 'john_doe@mydomain.com';
$_SESSION['password'] = 'mypassword';
?>
<iframe src="webmail/integration/test-iframe.php" style="width: 1000px; height: 600px;"></iframe>

* webmail/integration/test-iframe.php file:

<?php
	session_start();

	// Example of logging into user account using email and
	// password for incorporating into another web application

	// utilizing Aurora API
	include_once __DIR__.'/../libraries/afterlogic/api.php';

	if (class_exists('CApi') && CApi::IsValid())
	{
		// data for logging into account
		$sEmail = $_SESSION['email'];
		$sPassword = $_SESSION['password'];

		try
		{
			// Getting required API class
			$oApiIntegratorManager = CApi::Manager('integrator');

			// attempting to obtain object for account we're trying to log into
			$oAccount = $oApiIntegratorManager->LoginToAccount($sEmail, $sPassword);
			if ($oAccount)
			{
				// populating session data from the account
				$oApiIntegratorManager->SetAccountAsLoggedIn($oAccount);

				// redirecting to Aurora main page
				CApi::Location('../');
			}
			else
			{
				// login error
				echo $oApiIntegratorManager->GetLastErrorMessage();
			}
		}
		catch (Exception $oException)
		{
			// login error
			echo $oException->getMessage();
		}
	}
	else
	{
		echo 'AfterLogic API isn\'t available';
	}