AO Logo
 
  
  
  
Add Inbox
AO
AO Industries, Inc.
Application Infrastructure ProviderApplication Infrastructure Provider
Sign UpWhat's NewClient AreaContact UsSite Map
 
your location:   home page ··· aoserv platform ··· software components ··· aoserv client ··· how to ··· email howto ··· adding an email inbox
Adding an Email Inbox

Description
An email inbox is a restricted Linux account. It can be used for sending and receiving email using the POP2, POP3, IMAP, SPOP3, SIMAP, and SMTP protocols. If a shell connection is established, either via SSH or Telnet, the user is prompted to change their password. All other protocols are refused, including FTP.

AOSH Commands
add_username package username
add_linux_account username mailonly full_name "" "" "" email /usr/bin/passwd
add_linux_server_account username server ""
add_linux_acc_address address@domain.com server username
wait_for_linux_account_rebuild server
set_linux_server_account_password username server password

Simple API
/**
 * Creates a new email inbox.
 *
 * @param  aoClient     the SimpleAOClient to use
 * @param  packageName  the name of the Package
 * @param  username     the new username to allocate
 * @param  fullName     the user's full name
 * @param  server       the hostname of the server to add the user to
 * @param  address      the part of the email address before the @
 * @param  password     the password for the new user
 */
public static void addEmailInbox(
    SimpleAOClient aoClient,
    String packageName,
    String username,
    String fullName,
    String server,
    String address,
    String domain,
    String password
) throws IOException, SQLException {
    // Reserve the username
    aoClient.addUsername(packageName, username);

    // Indicate the username will be used for Linux accounts
    aoClient.addLinuxAccount(username, LinuxGroup.MAILONLY, fullName, null, null, null, LinuxAccountType.EMAIL, Shell.PASSWD);

    // Grant the new Linux account access to the server
    aoClient.addLinuxServerAccount(username, server, null);

    // Attach the email address to the new inbox
    aoClient.addLinuxAccAddress(address, domain, server, username);
    
    // Wait for rebuild
    aoClient.waitForLinuxAccountRebuild(server);

    // Set the password
    aoClient.setLinuxServerAccountPassword(username, server, password);
}

Full API
/**
 * Creates a new email inbox.
 *
 * @param  conn         the AOServConnector to use
 * @param  packageName  the name of the Package
 * @param  username     the new username to allocate
 * @param  fullName     the user's full name
 * @param  server       the hostname of the server to add the user to
 * @param  address      the part of the email address before the @
 * @param  password     the password for the new account
 *
 * @return  the new LinuxServerAccount
 */
public static LinuxServerAccount addEmailInbox(
    AOServConnector conn,
    String packageName,
    String username,
    String fullName,
    String server,
    String address,
    String domain,
    String password
) throws IOException, SQLException {
    // Resolve the Package
    Package pk=conn.getPackageTable().getPackage(packageName);

    // Reserve the username
    pk.addUsername(username);
    Username un=conn.getUsernameTable().getUsername(username);

    // Indicate the username will be used for Linux accounts
    un.addLinuxAccount(LinuxGroup.MAILONLY, fullName, null, null, null, LinuxAccountType.EMAIL, Shell.PASSWD);
    LinuxAccount la=un.getLinuxAccount();

    // Grant the new Linux account access to the server
    int lsaPKey=la.addLinuxServerAccount(server, LinuxServerAccount.getDefaultHomeDirectory(username));
    LinuxServerAccount lsa=conn.getLinuxServerAccountTable().getLinuxServerAccount(lsaPKey);

    // Find the Server
    Server se=conn.getServerTable().getServer(server);

    // Find the EmailDomain
    EmailDomain sd=se.getEmailDomain(domain);

    // Create the new email address
    int eaPKey=sd.addEmailAddress(address);
    EmailAddress ea=conn.getEmailAddressTable().getEmailAddress(eaPKey);

    // Attach the email address to the new inbox
    la.addEmailAddress(ea);

    // Wait for rebuild
    se.waitForLinuxAccountRebuild();

    // Set the password
    lsa.setPassword(password);
    
    // Return the new object
    return lsa;
}
Copyright © 2000-2024 AO Industries, Inc.