WebMail can be easily integrated into any existing system.
To bypass WebMail's login screen and enter user's email account directly, it is
required to set up some data that identify user in WebMail system. WebMail
provides Integration object for this purpose.
Usage of Integration object is simple.
1. Add a reference to WebMailPro.dll to your project (in Visual Studio 'Project->Add Reference...').
2. Import WebMailPro namespace:
using WebMailPro;
3. Create "Integration" object:
Integration integr = new Integration(@"c:\webmail\data", @"http://myserver/webmailpro/");
The first parameter is the path to the WebMail data folder. The same path is specified in 'web.config' file in the WebMail root folder.
The second parameter is the path to the WebMail root folder.
4. Now, for instance, we need to log a user into WebMail bypassing standard login screen. Let's call UserLoginByEmail method for this purpose:
integr.UserLoginByEmail(@"user@domian", "user", "password", WMStartPage.Mailbox);
WMStartPage is an enumeration determining the screen the user will be redirected to after logging in.
See also Usage Examples for details on user's account updates in WebMail system.
GetAccountById(id) | Gets Account object by id of user in the database (awm_accounts.id_acct), or null on error. |
GetAccountByMailLogin(email, login) |
Gets Account object by e-mail address and login or null on error.
email, login - required parameters. |
CreateUser(email, login, password) | Creates a user in WebMail database.
email, login, password - required parameters Default values are assigned to all other settings like POP3/IMAP4/SMTP servers, etc. |
CreateUserFromAccount(account) | Creates a user in WebMail database with settings specified in Account object. |
UserExists(email, login) |
Checks if the user exists in WebMail database.
email, login - required parameters. Returns true if the user exists, false if doesn't. |
UserLoginByEmail(email, login, startPage, password, recipient) | Performs login and redirects user into WebMail system.
email, login - required parameters. startPage - a constant determining the screen the user will be redirected to after logging in. password - may be equal to null recipient - e-mail address which will be put into To field. Is used in case of redirection to compose message screen (WMStartPage.NewMessage) only. |
All these methods may throw WebMailException. |
Value | Description |
Mailbox | Message list screen. |
NewMessage | Compose message screen. |
Settings | User's settings screen. |
Contacts | User's contacts screen (addressbook). |
Calendar | User's calendar screen. |
Account object (represents a user account in WebMail)
Value | Description |
ID (int) | Account unique identifier (awm_accounts.id_acct). |
Email (string) | Email address. |
DefaultAccount (bool) | Indicates if the account is default (primary), i.e. can be used for logging into WebMail. |
MailIncomingProtocol (WebMailPro.IncomingMailProtocol) | Protocol of the account.
Possible values: Pop3 - POP3 protocol. Imap4 - IMAP4 protocol. WMServer - communicating with local mail server. |
MailIncomingHost (string) | Incoming mail server address (e.g. mail.domain.com). |
MailIncomingPort (int) | Incoming mail server port number (110 for POP3, 143 for IMAP4). |
MailIncomingLogin (string) | Login for incoming mail server. |
MailIncomingPassword (string) | Password for incoming mail server. |
MailOutgoingHost (string) | Outgoing mail server address (e.g. mail.domain.com). |
MailOutgoingPort (int) | Outgoing mail server port number (25 for SMTP). |
MailOutgoingLogin (string) | Login for outgoing mail server. |
MailOutgoingPassword (string) | Password for outgoing mail server. |
FriendlyName (string) | A name to be added to e-mail address in From field of outgoing messages. |
GetMailAtLogin (bool) | Indicates if message receiving should be performed automatically after logging into WebMail under this account. |
Usage examples:
Example 1:
On the ASP.NET page you want to launch WebMail from, add the lines similar to the following:Example 2:
Integration integr = new Integration(@"c:\webmail\data", @"http://myserver/webmailpro/"); try { integr.UserLoginByEmail(@"user@domain", "user", "password", WMStartPage.NewMessage, "user1@domain"); } catch (WebMailException ex) { // handle exception }The code above will redirect to WebMail system and immediately open message compose screen for user 'user1@domain'.
Once UserLoginByEmail method called, there are two cases possible:
1. Specified email address was found in WebMail database. The user is redirected to the requested screen of the account. Email account properties are taken from the database (specified through "WebMail Settings" in "Administration Panel").
2. If there is no users with such credentials in the WebMail database or an error occurred, WebMailException will be thrown.
Example 3:Integration integr = new Integration(@"c:\webmail\data", @"http://myserver/webmailpro/"); try { integr.CreateUser("user@localhost", "user", "password"); } catch (WebMailException ex) { Response.Write(ex.Message); }This sample creates a user in WebMail database and displays error description on error.
Integration integr = new Integration(@"c:\webmail\data", @"http://myserver/webmailpro/"); try { Account acct = integr.GetAccountByMailLogin("user@localhost", "user", "password"); Response.Write(acct.Email); } catch (WebMailException ex) { // handle exception }This sample gets all user's data (as Account object) from WebMail database.