Community Knowledge Base

Automating Login to SmarterMail

Companies using SmarterMail can easily automate user entry into the mail application by configuring the auto-login functionality. The HTML code shown below demonstrates how you can make a text link on a website (e.g. "Log into your mail") that automatically logs a user in to the SmarterMail site. By putting this hidden form on a simple web page, you can fill in the "Domain", "Email Address", and "Password" information by hard-coding the data or through a scripting language like ASP, ASP.Net, or ColdFusion. This implementation of auto-login works seamlessly across domains, so the two applications do not have to be hosted on the same server.

Some notes about the example code listed below:

We have the form values set to generic text (e.g. "USERNAME_GOES_HERE") to show where you would hard code values that are submitted to the login page. You could also dynamically generate these values using a scripting language like ASP or ColdFusion. A sample ASP script would substitute var domain = "USERNAME_GOES_HERE"; with var domain = "<% =email %>".

The form action shown, https://DOMAIN_GOES_HERE, uses the default location of the SmarterMail Web Interface. If you have created a separate website for SmarterMail or if you assign a different IP address for SmarterMail within IIS, this action would have to be altered to reflect this change. For example, a modified form action might take the format of https://mail.smartertools.com. In addition, this code assumes that your SmarterMail site is secured with SSL/TLS. If it is not, be sure to change the var domain URL from https to http.

Auto-Login Sample HTML Code

	  <!DOCTYPE html> 
<html>
<head>
<meta charset="utf-8">
<script>
function autoLogin() {
var domain = "https://DOMAIN_GOES_HERE";
var username = "USERNAME_GOES_HERE";
var password = "PASSWORD_GOES_HERE";

var xhr = new XMLHttpRequest();
xhr.open('POST', domain + '/api/v1/auth/authenticate-user');
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
xhr.onload = function() {
if (xhr.status === 200) {
var success = JSON.parse(xhr.responseText);

if (!success.success) {
var res = "";
if(success.message)
res = success.message
else
res = success.status
document.getElementById("errors").innerText = res;
return;
}
window.location.href = success.autoLoginUrl;
}
else
{
document.getElementById("errors").innerText = failure.message || failure;
}
};
xhr.send(JSON.stringify({
username: username,
password: password,
retrieveAutoLoginToken: true
}));
}
</script>
</head>
<body onload="autoLogin()">
<div id="errors"></div>
</body>
</html>