Skip to content

Instantly share code, notes, and snippets.

@maestropanel2
Last active June 12, 2017 11:36
Show Gist options
  • Save maestropanel2/72b1f5bb50843922ddc621d4ccd65a60 to your computer and use it in GitHub Desktop.
Save maestropanel2/72b1f5bb50843922ddc621d4ccd65a60 to your computer and use it in GitHub Desktop.
Email list import to MaestroPanel
<#
.SYNOPSIS
Text dosyasi içindeki domain listesini MaestroPanel'e aktarır.
.DESCRIPTION
Text dosyasi içindeki domain listesini MaestroPanel'e aktarır.
.PARAMETER host
MaestroPanel'in çalıştığı sunucu IP adresi veya host ismi.
.PARAMETER apikey
MaestroPanel'de yetkili olan kullanıcıyı temsil eden API anahtarı.
.PARAMETER port
MaestroPanel'in çalıştığı Port numarası.
.PARAMETER list-file
Domain'lerin bulunduğu liste. Text dosyası ve satır satır alt alta olarak formatlanması gerekir.
.EXAMPLE
.\emailimport.ps1 -remote_host 192.168.0.4 -apikey 1_6c8a00e26765497698508b51622b3e25 -port 9715 -list_file C:\import\domains.txt
.LINK
https://github.com/maestropanel/listimport
.Notes
Author : Oğuzhan YILMAZ
Filename: emailimport.ps1
#>
[Cmdletbinding()]
Param(
[Parameter(Mandatory=$true)]
[string] $REMOTE_HOST,
[Parameter(Mandatory=$true)]
[string] $APIKEY,
[Parameter(Mandatory=$true)]
[string] $PORT = "9715",
[Parameter(Mandatory=$true)]
[string] $LIST_FILE
)
$MailList = Import-Csv $LIST_FILE
function CreateMailBox($mail){
$email = $mail.PrimarySmtpAddress.Split("@")
$account = $email[0]
$domain = $email[1]
$password = GetPassword(6)
$requestUrl = "http://$($REMOTE_HOST):$PORT/Api/v1/Domain/AddMailBox?format=json&suppress_response_codes=false"
$requestPrms = @{key=$APIKEY;name=$domain;account=$account;password=$password;quota=$mail.Quota;displayName=$mail.Name}
$result = Invoke-WebRequest -Uri $requestUrl -Method POST -Body $requestPrms | ConvertFrom-Json
Write-Host $result.Message
}
function GetPassword($length = 15) {
$punc = 46..46
$digits = 48..57
$letters = 65..90 + 97..122
# Thanks to
# https://blogs.technet.com/b/heyscriptingguy/archive/2012/01/07/use-pow
$password = get-random -count $length `
-input ($punc + $digits + $letters) |
% -begin { $aa = $null } `
-process {$aa += [char]$_} `
-end {$aa}
return $password
}
foreach ($mail in $MailList) {
CreateMailBox($mail)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment