• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Smartermail Import?

GOT-Jon

New Pleskian
So, we have a legacy server running Plesk 10.4. for windows. Before my time when ti was set up, they disabled mailenable and installed smartermail but never integrated it into plesk. It was managed manually and separately.

So now we are faced with needing to migrate this server to a new server with Plesk 12.

Obviously, the backups do not include any of the mail accounts, passow4rds, domains, etc because they were not created in plesk.

Is there some magical tool that can read the smartermail config and simply import all this data into plesk so we can back it up and migrate it to a new server?

Any suggestions on how to handle this scenario would be appreciated!
 
I have a powershell script that was written for PPA that may do the same thing, you may have to check the API docs for Plesk 10.4 but it should work. You could add another loop that goes over the domains first, then the users. It won't add their passwords, but that's okay, because it will allow them to reset their passwords when needed, and that's more to the point isn't it?

Code:
param (
  [Parameter(Mandatory,ValueFromPipeline)]
  [string]$domain
)
$ppaURL = "https://plesk.ip.addr:8443/enterprise/control/agent.php"
$ppaUser = "admin"
$ppaPass = "password"
$ppaHdrs = @{"HTTP_AUTH_LOGIN"=$ppaUser;"HTTP_AUTH_PASSWD"=$ppaPass}
$smURL = "http://smartermail.ip.addr/Services/svcDomainAdmin.asmx"
$smAction = "http://tempuri.org/GetDomainUsers"
$smUser = "admin"
$smPass = "password"

add-type @"
  using System.Net;
  using System.Security.Cryptography.X509Certificates;
  public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
    ServicePoint srvPoint, X509Certificate certificate,
    WebRequest request, int certificateProblem) {
      return true;
    }
  }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

#Get the site id
$idQueryXML = '<packet><site><get><filter><name>'+$domain+'</name></filter><dataset><hosting/></dataset></get></site></packet>'
$domXML = [xml](Invoke-WebRequest $ppaURL -Method post -ContentType 'text/xml' -Body $idQueryXML -Headers $ppaHdrs)
$siteid = [int]$domXML.packet.site.get.result.id
if($siteid < 0){
    #Get user list for domain
    $smartermail = New-WebServiceProxy -Uri $smURL
    $userXML = $smartermail.GetDomainUsers($smUser, $smPass, $domain)
    $users = $userXML.Users

    #insert users into PPA
    foreach($user in $users){
        $insert = '<packet><mail><create><filter><site-id>'+$siteid+'</site-id>'
        $insert += '<mailname><name>'+$user+'</name>'
        $insert += '<mailbox><enabled>true</enabled></mailbox></mailname></filter></create></mail></packet>'
        $insertXML = [xml](Invoke-WebRequest $ppaURL -Method post -ContentType 'text/xml' -Body $insert -Headers $ppaHdrs)
        Write-Host "Added $user to PPA DB"
}
}else{
    Write-Host "Domain $domain not found in PPA"
}
 
Last edited:
Hi Anthony,
I ran your script, it was unable to get the siteid so i had to hard code it in. Is there something else that has to be done on plesk for it to see the imported email accounts? When I ran it, it said that it imported the email accounts, but when i go to the panel nothing is listed. Any help would be much appreciated.
 
Hello Modal.Alert,

Did you replace all of the variables with appropriate values? THe fact that it didn't get the site ID is problematic and points at a connection failure.
 
Hi Anthony,
I tried the new script and still says domain doesn't exist, also when i do a echo $siteid it says 0, i tried by hard coding the $siteid, and it goes though the motions. I can see the email accounts it said its importing but still not showing up in plesk. Have any ideas?
 
Because i see the email accounts this is not a problem with smarter mail. Just cant figure out what to tweak in your script to get this thing going correctly.
 
Maybe this will help, this is what i get back when i run the invoke-webrequest

PS > Invoke-WebRequest $ppaURL -Method post -ContentType 'text/xml' -Body $idQueryXML -Headers $ppaHdrs


StatusCode : 200
StatusDescription : OK
Content : <?xml version="1.0"?>
<packet version="1.6.5.0">
<system>
<status>error</status>
<errcode>1001</errcode>
<errtext>You have entered incorrect username or password.</errtext>
</system> </p...
RawContent : HTTP/1.1 200 OK
Transfer-Encoding: chunked
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Type: text/xml
Date: Wed,...
Forms : {}
Headers : {[Transfer-Encoding, chunked], [Connection, keep-alive], [Pragma, no-cache], [Cache-Control, no-store, no-cache, must-revalidate, post-check=0,
pre-check=0]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 206
 
Ok, just tried it with the admin account. i see the emails added into the db using this query:

SELECT CONCAT_WS('@',mail.mail_name,domains.name) FROM domains,mail WHERE domains.name='demo-account.com';

But when i look in the plesk panel nothing shows, do you think maybe its not updating some other table or something like that?
 
PM your edited script, just blank out the password you are using for smartermail and plesk. Put 3 # symbols in place, that way I know you are setting them.
 
Ok, just tried it with the admin account. i see the emails added into the db using this query:

SELECT CONCAT_WS('@',mail.mail_name,domains.name) FROM domains,mail WHERE domains.name='demo-account.com';

But when i look in the plesk panel nothing shows, do you think maybe its not updating some other table or something like that?
It is possible, this was written for plesk 11.5, which is what PPA used, I may have to alter the script for 12.5. That would be good for me to know as well.
 
Hello modal.Alert,

Reading back over your responses I noticed:

<errtext>You have entered incorrect username or password.</errtext>

That pretty clearly defines the issue. You did not populate the username and password fields with proper values.

Unless of course you just ran this one command manually, which wouldn't have the auth headers included.
 
Plesk API docs say as of version 12 you should omit the version attribute from the packet tag, I have adjusted the above code to reflect this.
 
Double checking http://docs.plesk.com/en-US/12.5/ap...ing-mail/creating-mail-accounts.34499/#o34501 This code should work unless your url or authentication values are wrong. Try the new version make sure you have populated all variables with correct information, for ref, here is a list:

$ppaURL = "https://plesk.ip.addr:8443/enterprise/control/agent.php"
$ppaUser = "admin"
$ppaPass = "password"

$smURL = "http://smartermail.ip.addr/Services/svcDomainAdmin.asmx"

$smUser = "admin"
$smPass = "password"
 
Hello modal.Alert,

Reading back over your responses I noticed:

<errtext>You have entered incorrect username or password.</errtext>

That pretty clearly defines the issue. You did not populate the username and password fields with proper values.

Unless of course you just ran this one command manually, which wouldn't have the auth headers included.

I strongly agree on this one. I tried fixing the same problem using this solution. It does work.
 
Does anybody have an updated script that can run on machines running Windows 2012 R2 or later?
 
Last edited:
Back
Top