Importing mailboxes to Microsoft 365 using imapsync

When you start migrating e-mail service to Microsoft 365, it is often necessary to import mailboxes and emails from the old mail server. You can use paid solutions, but in this post I will show you the possible use of the imapsync. If you can connect to the e-mail account on the old server via IMAP protocol, you can use a simple script that can automate this process.

$csvFile = @(Import-CSV C:\Imapsync\sync_users.csv)

foreach ($line in $csvFile) {

   $user1=$line.user1
   $user2=$line.user2
   $pass1=$line.pass1
   $pass2=$line.pass2
   $authuser1=$line.authuser1
   $authuser2=$line.authuser2

 Write-Output Sync emails from $user1 to $user2 

 C:\Imapsync\imapsync.exe --host1 mail.domain1.com --port1 143 --user1 $user1 --authuser1 $authuser1 --password1 $pass1 `
                          --host2 outlook.office365.com --port2 993 --user2 $user2 --authuser2 $authuser2 --password2 $pass2 -ssl2 --automap  
 }

Csv file should have the following structure:

user1,user2,pass1,pass2,authuser1,authuser2
[email protected],[email protected],Password1,Password2,[email protected],[email protected]
[email protected],[email protected],Password1,Password2,[email protected],[email protected]

You should keep in mind that the synchronization is performed by another user who should have the appropriate permissions for the synchronized account. It can be, for example, an administrator account – in our case it is the [email protected] account on the server from which we import the mail.

On the Microsoft 365 side, the user account must have an appropriate license and an e-mail account set up. Permissions for the synchronizing user – in our case, [email protected] can be set using the command below.

Get-Mailbox [email protected] | Add-MailboxPermission -User [email protected] -AccessRights FullAccess -InheritanceType All  

The migration process depends on the size of the synchronized mailbox and the imapsync tool itself has many settings and parameters. In most cases, you have to set the synchronization parameters individually and for this purpose, please refer to documentation.

1 1 vote
Article Rating
Subscribe
Notify of
guest

0 comments
Inline Feedbacks
View all comments