Command prompt utilities - batching

Discussion forum for Enterprise Edition.
Post Reply
Wholesaledial
Posts: 2
Joined: Wed Jan 15, 2014 2:11 am

Command prompt utilities - batching

Post by Wholesaledial »

Are there any command prompt utilities for MailEnable that can perform the following?

Add mailboxes
Remove mailboxes
Add Alias
Remove Alias
Change mailbox password

I'm looking to integrate with an existing billing package that supports running commands on certain actions. Command line utilities would allow me to finish integrating MailEnable.

Thanks.

ShawnKHall
Posts: 113
Joined: Wed Apr 06, 2005 12:03 am
Location: California, USA
Contact:

Re: Command prompt utilities - batching

Post by ShawnKHall »

Late to the party but I just needed to do the aliasing part because Plesk is inconsistent when adding aliases from their CLI app. This batch file will do it for you.

What it does:
1) has constant assignments for mapping the account & mailbox, then each of the alias domains you want to include. (you could parse CLI input to populate these if you wanted)
2) ensures the address-map file ends with a carriage return (to prevent data corruption)
3) attempts to map the alias using Plesk (remove this part if you're not using Plesk)
4) parses the aliases list (splits on comma)
5) passes an individual alias
6) tests for the existence of the alias mapping and adds it if not found

Run it like so:

Code: Select all

alias4bob.bat "robert"

Here's the code:

Code: Select all

@ECHO OFF

:: 1-constants
SET "address=bob"
SET "domain=example.com"
SET "domainaliases=example.com,example.org"
SET "addressmap=C:\Program Files (x86)\Parallels\Plesk\Mail Servers\Mail Enable\Config\ADDRESS-MAP.TAB"
SET "alias=%~1"

:: 2-ensure address map ends in CRLF
findstr /V $ "%addressmap%" >NUL && ECHO.>>"%addressmap%"

:: 3-attempt Plesk-based mapping
:: sometimes it does not actually modify the address-map.tab file, so the code below does that.
"C:\Program Files (x86)\Parallels\Plesk\bin\mail.exe" -u %address%@%domain% -aliases add:"%alias%"

:: 4-parse for each domain alias
CALL :parse "%domainaliases%"
GOTO :EOF

:: 5-subroutine to process list items
:parse
SETLOCAL
SET "list=%~1"
ECHO.%list%
FOR /f "tokens=1* delims=," %%a IN ("%list%") DO (
	IF NOT "%%a"=="" CALL :process "%%~a"
	IF NOT "%%b"=="" CALL :parse "%%~b"
)
ENDLOCAL
EXIT /b

:: 6-subroutine to test for and inject new alias
:process
SETLOCAL
SET "domalias=%~1"
ECHO.Checking "%alias%@%domalias%"
findstr /I /C:"[SMTP:%alias%@%domalias%]" "%addressmap%" >NUL
IF "%ERRORLEVEL%"=="1" (
ECHO.Adding: "%alias%@%domalias%"
>> "%addressmap%" ECHO.[SMTP:%alias%@%domalias%]	[SF:%domain%/%address%]		%domain%	0
) ELSE (
ECHO.Exists: "%alias%@%domalias%"
)
ENDLOCAL
EXIT /b
Be aware that the tabs are CRITICAL for proper behavior. If the line after "ECHO.Adding:" does not have tabs in it when you copy this into your batch file please review your address-map.tab file and ensure that the appropriate number of tabs exists between each column (no spaces!).
-Shawn

Post Reply