hMailServer - 批量创建用户 - vbs脚本

需求:通过csv文件,能批量导入邮箱地址和密码,如

chen10,nfhe7384,hmail2.demo.anqun.org
chen11,nfhe755t,hmail2.demo.anqun.org
chen12,nfhe755t,hmail3.demo.anqun.org

尝试:通过hMailServer的COM API,用vbs脚本可从csv文件读取邮箱用户、密码和域名。

脚本内容:

'#####the script#####
'# The EntryType can be one of two options, User or Alias. If the EntryType is User, then:
'#
'# EntryType = User
'# Field1 = Uername
'# Field2 = Password
'# Field3 = DomainName
'# Field4 = FirstName
'# Field5 = LastName
'#
'# If the EntryType is Alias, then:
'# EntryType = Alias
'# Field1 = AliasName
'# Field2 = ForwardingEmail
'# Field3 = DomainName
'#
'# To add USERS, for example, your CSV file should have the structured information (type, strUsername, strPassword, strDomain, strPersonFirstName, strPersonLastName), like below:
'# User,tjones,mypassword,jones.com,Tommy,Jones
'#
'# To add ALIAS, for example, your CSV file should have the structured information (type, strAlias, strAliasUsername, strDomain), like below:
'# Alias,tommy,tjones@jones.com,jones.com
'#
'# This would create a user names tjones@jones.com in the jones.com domain and an alias tommy@jones.com which will forward all e-mail to tjones@jones.com in the jones.com domain.
'####################

Option Explicit
Dim Elog
Dim obBaseApp
Dim objFSO
Dim objTextFile
Dim strNewAlias,i

Dim failed
Dim added
Dim domainsAdded

failed = 0
added = 0
domainsAdded = 0

'#####################################################################
'# Custom Variables regarding HMAIL admin password and file to be read
'#####################################################################
Dim hAdminpwd
Dim CSVFile
hAdminpwd = "hmailmima"
CSVFile = "bulk.csv"

Set Elog = CreateObject("hMailServer.EventLog")
Set obBaseApp = CreateObject("hMailServer.Application")

Call obBaseApp.Authenticate("Administrator",hAdminpwd) '*** N.B. 1. set your administrator password in this line

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(CSVFile, ForReading) 'N.B. 2. Set your CSV path/filename in this line
On Error resume next
Do While objTextFile.AtEndOfStream <> True
    strNewAlias = split(objTextFile.Readline, ",")

    'Select Case lcase(trim(strNewAlias(0)))
       'Case "user"
          ' AddUser trim(strNewAlias(1)), trim(strNewAlias(2)), trim(strNewAlias(3)),trim(strNewAlias(4)),trim(strNewAlias(5))
       'Case "alias"
          'AddAlias trim(strNewAlias(1)), trim(strNewAlias(2)), trim(strNewAlias(3))
    'End Select
    
    AddUser trim(strNewAlias(0)), trim(strNewAlias(1)), trim(strNewAlias(2))
    
    If err.Number <> 0 Then    'error handling:
     Elog.Write("Failed add (probably duplicate)" & Chr(34) & vbTab & Chr(34) & strNewAlias(0) _
     & "," & strNewAlias(1) & "," & strNewAlias(2) & "," & strNewAlias(3))
     failed = failed + 1
     err.Clear
    Else
     added = added + 1
    End If
Loop
On Error goto 0
Elog.Write("Domains Added Sucessfully    = " & domainsAdded)
Elog.Write("Accounts Added Sucessfully   = " & added)
Elog.Write("Failed or Duplicate Accounts = " & failed)
Wscript.Echo ("Domains Added Sucessfully    = " & domainsAdded & VbNewLine _
            & "Accounts Added Sucessfully   = " & added & VbNewLine _
            & "Failed or Duplicate Accounts  = " & failed & VbNewLine & VbNewLine _
            & "See hmailserver_events.log for list of duplicates (if any)")

'###################
'# Usefull functions
'###################
Sub AddAlias(strAlias,strEmailAddress,strDomain)

   AddDomain strDomain

   Dim obDomain
   Dim obAliases
   Dim obNewAlias

   Set obDomain = obBaseApp.Domains.ItemByName(strDomain)
   Set obAliases = obDomain.Aliases
   Set obNewAlias = obAliases.Add()
   
   obNewAlias.Name = strAlias & "@" & strDomain 'username
   obNewAlias.Value = strEmailAddress 'password
   obNewAlias.Active = 1 'activates user
   obNewAlias.Save() 'saves account
   
   Set obNewAlias = Nothing
   Set obAliases = Nothing
   Set obDomain = Nothing
   
End Sub

'Sub AddUser(strUsername, strPassword, strDomain, strPersonFirstName, strPersonLastName)
Sub AddUser(strUsername, strPassword, strDomain)
   
   AddDomain strDomain
   
   Dim obDomain
   Dim obAccounts
   Dim obNewAccount

   Set obDomain = obBaseApp.Domains.ItemByName(strDomain)
   Set obAccounts = obDomain.Accounts
   Set obNewAccount = obAccounts.Add()
   
   obNewAccount.Address = strUsername & "@" & strDomain 'username
   obNewAccount.Password = strPassword 'password
   'obNewAccount.PersonFirstName = strPersonFirstName
   'obNewAccount.PersonLastName = strPersonLastName
   obNewAccount.Active = 1 'activates user
   obNewAccount.Maxsize = 0 'sets mailbox size, 0=unlimited
   obNewAccount.Save() 'saves account
 
   Set obNewAccount = Nothing
   Set obDomain = Nothing   
   Set obAccounts = Nothing
 
End Sub

Sub AddDomain(strDomain)
   Dim obNewDomain
   Set obNewDomain = obBaseApp.Domains.Add()
   obNewDomain.Name = strDomain
   obNewDomain.Active = True

   On Error resume next
   obNewDomain.Save()
   If err.Number = 0 Then
    domainsAdded = domainsAdded + 1
   End If
   err.Clear
 
   obBaseApp.Domains.Refresh()
End Sub

参考:

Windows 2012 R2 无法安装 .NET Framework 3.5 - .NET Framework 2.0 - KB5029915

现象:Windows 2012 R2 系统,无法通过“服务器管理器”和DISM命令安装.NET Framework 3.5,即使指定SxS安装源路径,一样报错。

尝试:查看已安装的Windows更新,检索其中与 .NET Framework 3.5 的更新。删除其中的 KB5029915 后,即可安装 .NET Framework 3.5。原因可能是当 Windows 2012 R2没有安装 .NET Framework 3.5 组件时进行了Windows Update,安装.NET Framework 3.5 的安全更新后,导致不能正常安装 .NET Framework 3.5。

参考:

magento - ValidationSchemaException 出错 - esconfig.xsd - 因为cPanel环境升级xml版本导致

现象:magento首页或单页内容显示正常,但在产品分类页提示出错,如:

Exception #0 (Magento\Framework\Config\Dom\ValidationSchemaException): Processed schema file: public_html/vendor/magento/module-elasticsearch/etc/esconfig.xsd
complex type 'mixedDataType': The content model is not determinist.
Line: 18

#1 Magento\Framework\Config\Dom->_initDom() called at [vendor/magento/framework/Config/Dom.php:116]
#2 Magento\Framework\Config\Dom->__construct() called at [vendor/magento/framework/Config/Reader/Filesystem.php:196]
#3 Magento\Framework\Config\Reader\Filesystem->_createConfigMerger() called at [vendor/magento/framework/Config/Reader/Filesystem.php:151]
#4 Magento\Framework\Config\Reader\Filesystem->_readFiles() called at [vendor/magento/framework/Config/Reader/Filesystem.php:132]

尝试:将文件 vendor/magento/module-elasticsearch/etc/esconfig.xsd 中的这行内容删除或注释掉:<xs:element type="xs:string" name="default" minOccurs="1" maxOccurs="1" />

原因可能是cPanel环境中,升级了xml,导致软件不兼容。

参考:

debian 12.2系统里安装 iredmail-enterprise-1.0-beta1-linux-amd64 的两个问题

尝试在debian 12.2系统里安装 iredmail-enterprise-1.0-beta1-linux-amd64。发现有两个问题:

  1. web安装程序报错。搜索得,ntp 包对应的服务名是 ntpsec ,不是ntp 。 服务配置文件是:/lib/systemd/system/ntpsec.service
    TASK [ntp] Install ntp/chrony server to sync local time.
    ok: ntp

    TASK [ntp] Enable and restart ntp/chrony service.
    failed: ntp
    [ERROR] task error: failed in restarting service ntp: exit status 5, Failed to restart ntp.service: Unit ntp.service not found.

  2. 通过web/admin 管理添加的用户,外网发信到这个用户会报错:said: 550 5.1.1 mailto:liu@iredmail.anqun.org: Recipient address rejected: User unknown (in reply to RCPT TO command) 这个用户是能登录到 roundcube。从服务器的shell里,也能通过命令行成功发信。作为对比,用web/iredadmin添加的用户,正常。删除之前报错的域,重新使用iredadmin添加回同一个域和用户,能从外网收信。尝试的解决方法是手动补上缺失的 forwardings 表内容:
    INSERT INTO forwardings (address, forwarding, domain, dest_domain, is_forwarding)
    VALUES ('liu@iredmail.anqun.org', 'liu@iredmail.anqun.org','iredmail.anqun.org', 'iredmail.anqun.org', 1);

参考:

在grml debian 的 livecd overlay 文件系统里启动 mariadb-server

问题:在 grml 的急救系统里无法启动 mariadb-server,报错:/usr/sbin/mariadbd $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=killed, signal=ABRT)

尝试:在 mysqld 的配置内容中,增加一行 innodb_flush_method = fsync

参考: