Introduction
This API allows applications to communicate with backend code of WebMail Pro. In essence, you can create your custom frontend which would interact with WebMail Pro backend via Web API. Note that the application which uses Web API doesn't have to be a web application, you can use this API in mobile, desktop and server applications as well.
Usually, one would call SystemGetAppData method to obtain authentication token, then log user in with SystemLogin method call. After that, it's possible to obtain list of folders, request message list, read and send mails, etc.
Note that you can also use PHP API to manipulate messages, folders etc. if your application and WebMail Pro are installed on the same server. Also, you can manipulate domains and accounts via REST API.
Getting Started
To start working with specific user account via API, you'll need to initialize API by performing SystemGetAppData request. Below, please find an example of the code written in C#, which performs the request.
string url = "https://webmail.afterlogic.com/?/Ajax/";
using (var client = new WebClient())
{
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string strData = "Action=SystemGetAppData";
strData = client.UploadString(url, strData);
Console.WriteLine(strData);
}
The following points are important in this regard:
1) The entry point for making all the Web API calls is WebMail Pro installation URL with /?/Ajax/ appended.
2) If the installation is accessed via HTTPS, URL for API call needs to have https:// there, even if the installation is configured to redirect from http:// automatically.
3) All the Web API calls are to be performed using POST; WebClient.UploadString method used in the above code always uses POST.
4) Content-Type of the request must be set to "application/x-www-form-urlencoded".
Upon performing the request, store Token value returned by this request. Below please see the example of response structure pertaining to where exactly Token is found.
Then, log user into their WebMail Pro account by running SystemLogin request. This request returns response of the following kind:
{
"Action":"SystemLogin",
"AccountID":1,
"Result":
{
"AuthToken":"89e307c653d701c17d61f2f116dba618"
},
"@Time":1.7640471458435
}
From the above result, AuthToken and AccountID values need to be stored.
The three items we have stored - Token, AuthToken and AccountID will be required for performing all the further requests.
Error Codes
Typical response returned on failure looks like this:
{
"Action":"SystemLogin",
"Result":false,
"@Time":3.7776839733124,
"ErrorCode":102,
"ErrorMessage":"TAG1 NO Authentication failed."
}
The following ErrorCode values are supported:
- 101 - invalid token;
- 102 - authentication failure;
- 103 - invalid data;
- 104 - database error;
- 999 - method not found.
Methods
You can find the list of currently supported Web API methods below. All the methods return the response in JSON format.
Note that if your application runs on iOS or OS X, JSON data are represented as NSDictionary object. If particular key starts with @ character, you should use objectForKey method to retrieve the value:
[collection objectForKey:@"@Collection"];
The following would be incorrect:
[collection valueForKey:@"@Collection"];
System methods
SystemGetAppData
Web API initialization requests. There are 2 cases when this request needs to be performed:
1) When opening login page, the following data will be returned:
- Token - token string which is used for protection from forged requests and which needs to be sent in each subsequent request;
- data needed for displaying login page, such as SiteName, DefaultLanguage, DefaultTheme, etc.
2) Right after logging in, to obtain user settings and account list.
Request Item | Type | Sample value | Description |
AccountID | int | 0 | ID of user logged in, 0 if not logged in |
Action | string | "SystemGetAppData" | |
Token | string | "169874786e1d429e20fd993800a8c08c" | string obtained with this request earlier, or an empty string |
AuthToken | string | "89e307c653d701c17d61f2f116dba618” | string obtained with SystemLogin request Not needed if client supports cookies or if user isn't logged in yet. |
Sample response:
{
"Action":"SystemGetAppData",
"Result":
{
"Auth":true,
"User":// null, if Auth = false, i.e. not logged in
{
"IdUser":1,
"MailsPerPage":10,
"ContactsPerPage":20,
"AutoCheckMailInterval":1,
"DefaultEditor":1,
"Layout":0,
"DefaultTheme":"DeepForest",
"DefaultLanguage":"Russian",
"DefaultLanguageShort":"ru",
"DefaultDateFormat":"DD Month YYYY",
"DefaultTimeFormat":1,
"AllowCompose":true,
"AllowReply":true,
"AllowForward":true,
"AllowFetcher":false,
"SaveMail":0,
"ThreadsEnabled":true,
"UseThreads":true,
"SaveRepliedMessagesToCurrentFolder":true,
"DesktopNotifications":true,
"AllowChangeInputDirection":false,
"EnableOpenPgp":true,
"AllowAutosaveInDrafts":true,
"AutosignOutgoingEmails":false,
"OutlookSyncEnable":true,
"MobileSyncEnable":true,
"ShowPersonalContacts":true,
"ShowGlobalContacts":true,
"IsCollaborationSupported":true,
"AllowFilesSharing":false,
"IsFilesSupported":true,
"IsHelpdeskSupported":true,
"IsHelpdeskAgent":true,
"AllowHelpdeskNotifications":false,
"LastLogin":0,
"AllowVoice":false,
"VoiceProvider":"",
"SipRealm":"",
"SipWebsocketProxyUrl":"",
"SipOutboundProxyUrl":"",
"SipCallerID":"",
"TwilioNumber":"",
"TwilioEnable":true,
"SipEnable":true,
"SipImpi":"",
"SipPassword":"",
"FilesEnable":true,
"AllowCalendar":true,
"Calendar":
{
"ShowWeekEnds":true,
"ShowWorkDay":true,
"WorkDayStarts":1,
"WorkDayEnds":18,
"WeekStartsOn":0,
"DefaultTab":3,
"SyncLogin":"myemail@afterlogic.com",
"DavServerUrl":"",
"DavPrincipalUrl":"",
"AllowReminders":true
},
"CalendarSharing":true,
"CalendarAppointments":true,
"SocialAccounts":[],
"IsDemo":false
},
"TenantHash":"",
"IsMobile":0,
"IsMailsuite":false,
"HelpdeskSiteName":"",
"HelpdeskIframeUrl":"",
"HelpdeskRedirect":false,
"HelpdeskThreadId":0,
"HelpdeskActivatedEmail":"",
"HelpdeskForgotHash":"",
"ClientDebug":true,
"MailExpandFolders":false,
"HtmlEditorDefaultFontName":"",
"HtmlEditorDefaultFontSize":"",
"AllowSaveAsPdf":false,
"LastErrorCode":0,
"Token":"169874786e1d429e20fd993800a8c08c",
"ZipAttachments":true,
"AllowIdentities":true,
"SocialEmail":"",
"SocialIsLoggedIn":false,
"Links":
{
"ImportingContacts":"",
"OutlookSyncPlugin32":"http://www.afterlogic.com/download/OutlookSyncAddIn.msi",
"OutlookSyncPlugin64":"http://www.afterlogic.com/download/OutlookSyncAddIn64.msi",
"OutlookSyncPluginReadMore":"http://www.afterlogic.com/wiki/Outlook_sync_(Aurora)"
},
"LoginStyleImage":"",
"AppStyleImage":"",
"HelpdeskStyleImage":"",
"HelpdeskThreadAction":"",
"Default":1,// not available if Auth = false, i.e. not logged in
"Accounts":// null, if Auth = false, i.e. not logged in
[
{
"AccountID":1,
"Email":"myemail@afterlogic.com",
"FriendlyName":"\u041d\u0430\u0434\u0435\u0436\u0434\u0430 \u0428\u0438\u043f\u0438\u043a\u0430",
"Signature":
{
"Signature":"<div data-crea=\"font-wrapper\" style=\"font-family: Tahoma; font-size: 16px; direction: ltr\">/ \u041d\u0430\u0434\u0435\u0436\u0434\u0430 \u0428\u0438\u043f\u0438\u043a\u0430</div>",
"Type":1,
"Options":1
}
}
],
"App":
{
"AllowUsersChangeInterfaceSettings":true,
"AllowUsersChangeEmailSettings":true,
"AllowUsersAddNewAccounts":true,
"AllowOpenPGP":true,
"AllowWebMail":true,
"DefaultTab":"contacts",
"AllowIosProfile":true,
"PasswordMinLength":0,
"PasswordMustBeComplex":false,
"AllowRegistration":true,
"AllowPasswordReset":true,
"RegistrationDomains":["aaa"],
"RegistrationQuestions":["sdfsdfsdf"],
"SiteName":"AfterLogic WebMail Pro",
"DefaultLanguage":"Russian",
"DefaultLanguageShort":"ru",
"DefaultTheme":"DeepForest",
"Languages":
[
{"name":"English","value":"English"},
{"name":"Deutsch","value":"German"},
...
],
"Themes":["Default","White","DeepForest","Autumn","Funny"],
"DateFormats":["MM/DD/YYYY","DD/MM/YYYY","DD Month YYYY"],
"AttachmentSizeLimit":10240000,
"ImageUploadSizeLimit":0,
"FileSizeLimit":0,
"AutoSave":true,
"IdleSessionTimeout":0,
"AllowInsertImage":true,
"AllowBodySize":false,
"MaxBodySize":600,
"MaxSubjectSize":255,
"AllowPrefetch":true,
"AllowLanguageOnLogin":true,
"FlagsLangSelect":true,
"LoginFormType":0,//0 for email, 3 for login, 4 for both
"LoginSignMeType":1,
"LoginAtDomainValue":"localhost",
"DemoWebMail":false,
"DemoWebMailLogin":"myemail@afterlogic.com",
"DemoWebMailPassword":"12345",
"GoogleAnalyticsAccount":"",
"CustomLoginUrl":"",
"CustomLogoutUrl":"",
"ShowQuotaBar":true,
"ServerUseUrlRewrite":false,
"ServerUrlRewriteBase":"",
"IosDetectOnLogin":false,
"AllowContactsSharing":false,
"LoginDescription":""
},
"Plugins":[]
},
"@Time":0.22752904891968
}
SystemLogin
Log user into their WebMail Pro account.
Request Item | Type | Sample value | Description |
AccountID | int | 0 | optional |
Action | string | "SystemLogin" | |
Email | string | "myemail@afterlogic.com" | email of account we're logging into |
IncLogin | string | "" | optional if SystemGetAppData returned LoginFormType value 0 (default value) |
IncPassword | string | "12345" | |
SignMe | int | 1 | optional; if set to 1, WebMail Pro will log this user in next time automatically |
Token | string | "169874786e1d429e20fd993800a8c08c" | |
Sample response:
{
"Action":"SystemLogin",
"AccountID":1,
"Result":
{
"AuthToken":"89e307c653d701c17d61f2f116dba618" // used to maintain sessions on cookieless clients
},
"@Time":1.7640471458435
}
SystemLogout
Log user out of their WebMail Pro account.
Request Item | Type | Sample value | Description |
AccountID | int | 1 | ID of user logged in |
Action | string | "SystemLogout" | |
AuthToken | string | "89e307c653d701c17d61f2f116dba618” | string obtained with SystemLogin. Not needed if client supports cookies. |
Token | string | "169874786e1d429e20fd993800a8c08c" | |
Sample response:
{
"Action":"SystemLogout",
"AccountID":1,
"Result": true,
"@Time":1.7640471458435
}
Web API methods
• Receiving mail
• Sending mail
• Files
• Uploading files