Home » Blog » Exchange Server » Migrate MSG File to Microsoft Exchange Server

Migrate MSG File to Microsoft Exchange Server

author
Published By siddharth
Anuraag Singh
Approved By Anuraag Singh
Published On October 5th, 2024
Reading Time 7 Minutes Reading
Category Exchange Server

There are times when admins have to migrate MSG file to Microsoft Exchange server environment. This transfer of data is often the case when a major shift in organizational structure. Or when admins decide to shift the on-device MSG backups into a single server for easier access.

We can’t just start right away there are a few preparatory steps that we have to complete first.  When we study the Microsoft’s original documentation on MSG Files it becomes quite learn as to why a direct import is not possible.

It all comes down to the difference in the structure of .msg and .edb (the default storage format in exchange). While the former splits each message into separate entities the latter maintains a single cohesive file.

The reason itself has no effect on the method. So without further ado let’s look at a method that is quite possibly the easiest one out there.

What is the Default Way to Migrate MSG File to Microsoft Exchange Server?

The easiest way is to drag and drop MSG to an Outlook Client Connected with Exchange Server. However, this can’t be done if a user does not have an Exchange mailbox in their name.

However, this facility is only available for Classic clients as the new version of Outlook desktop is designed to operate in conjunction with the M365 cloud.

Moreover, when there are thousands of MSG files and each is to be put in a different account, Drag and Drop won’t suffice. Not only that it also creates a lot of room for error which ends up delaying the task.

So instead admins can try out some alternative methods or distribute the MSG files to individual users and ask them to update on their end.

Secondary Tactic 

As we know Exchange Server Prevent a direct deposit of raw MSG files. However, we can use an alternative route. The idea is to first use a single Outlook Profile to convert the MSG files into PST then use the PowerShell commands to attach these new PST files in their respective Exchange Server Mailboxes.

That is why the major one is to first prepare a folder list for each user with a name that is the exact replica of their Exchange mailbox ID.

Then install and set up an Outlook classic edition.

After this, the rest of the steps are manual intensive adding the MSG by drag and drop and Exporting the result into the PST format.

Once done, establish a PowerShell connection between the workstation and Exchange Server and deposit the mailboxes with the help of the commands.

Bring MSG Files in the Exchange Server Environment With Pure PowerShell Script

# Requires -Version 3.0
# Import required Exchange Management module if needed
# Import-Module ExchangeWebServices
Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
function Import-MsgToExchange {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$MsgFilePath,

[Parameter(Mandatory=$true)]
[string]$MailboxEmail,

[Parameter(Mandatory=$true)]
[System.Management.Automation.PSCredential]$Credential,

[Parameter(Mandatory=$true)]
[string]$ExchangeServer,

[Parameter(Mandatory=$false)]
[switch]$UseEWSImpersonation
)

try {
# Initialize Exchange Web Services
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1)
$service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.NetworkCredential($Credential.UserName, $Credential.GetNetworkCredential().Password)
$service.Url = "http://$ExchangeServer/EWS/Exchange.asmx"

# Set up impersonation if requested
if ($UseEWSImpersonation) {
$service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxEmail)
}

# Create new email message
$email = New-Object Microsoft.Exchange.WebServices.Data.EmailMessage($service)

# Read MSG file content
$bytes = [System.IO.File]::ReadAllBytes($MsgFilePath)

# Set MIME content
$email.MimeContent = New-Object Microsoft.Exchange.WebServices.Data.MimeContent("UTF-8", $bytes)

# Set message flag to indicate it's not a draft
$PR_MESSAGE_FLAGS = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(3591, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer)
$email.SetExtendedProperty($PR_MESSAGE_FLAGS, 1)

# Save to Inbox
$email.Save([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)

Write-Host "Successfully imported $MsgFilePath to $MailboxEmail" -ForegroundColor Green
return $true
}
catch {
Write-Error "Failed to import MSG file: $_"
return $false
}
}

function Import-MultipleMsg {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$FolderPath,

[Parameter(Mandatory=$true)]
[string]$MailboxEmail,

[Parameter(Mandatory=$true)]
[System.Management.Automation.PSCredential]$Credential,

[Parameter(Mandatory=$true)]
[string]$ExchangeServer,

[Parameter(Mandatory=$false)]
[switch]$UseEWSImpersonation
)

$msgFiles = Get-ChildItem -Path $FolderPath -Filter "*.msg" -Recurse
$successCount = 0
$failCount = 0

foreach ($msgFile in $msgFiles) {
Write-Host "Processing: $($msgFile.FullName)" -ForegroundColor Yellow
$result = Import-MsgToExchange -MsgFilePath $msgFile.FullName -MailboxEmail $MailboxEmail -Credential $Credential -ExchangeServer $ExchangeServer -UseEWSImpersonation:$UseEWSImpersonation

if ($result) {
$successCount++
} else {
$failCount++
}
}

Write-Host "Import complete. Successful: $successCount, Failed: $failCount" -ForegroundColor Cyan
}

# Example usage
try {
# Get credentials securely
$cred = Get-Credential -Message "Enter your Exchange credentials"

# Set variables
$exchangeServer = "your-exchange-server.domain.com"
$mailboxEmail = "user@yourdomain.com"
$msgFolder = "C:\Path\To\MSG\Files"

# Import a single MSG file
$singleFile = "C:\Path\To\Single\email.msg"
Import-MsgToExchange -MsgFilePath $singleFile -MailboxEmail $mailboxEmail -Credential $cred -ExchangeServer $exchangeServer

# Import multiple MSG files
Import-MultipleMsg -FolderPath $msgFolder -MailboxEmail $mailboxEmail -Credential $cred -ExchangeServer $exchangeServer
}
catch {
Write-Error "Script error: $_"
}

Note: This is a sample script and should only be used in a live environment after testing. Moreover, we have to prepare a seperate such a sub routine as the current version of EWS Managed API cannot use the UploadItems function.

Using this script admins will be able to either import one or multiple .msg files from a folder into a mailbox.
It uses secure credentials and connection protocol to link with the destination Exchange Server via the Exchange Web Services (EWS) API.

If this feels too tough you can instead use an automated tool, the explanation can be found below.

Professionally Migrate MSG File to Microsoft Exchange Server

SysTools Import Tool is your best bet to securely transfer all MSG files from a local machine to the Exchange Server. Unlike the manual method, this tool rarely causes an Exchange Server database corruption issue and thus is completely safe to use.

Download Now Purchase Now

The easily accessible GUI hides advanced algorithms in the background that accomplish the task in record time. You can put in date filters, and validate the Admin credentials for a bulk transfer.

Steps to Perform MSG to Exchange Transfer Via the Tool

Launch the utility on your workstation, select Source as MSG and Destination as Exchange Server.

Source & Destination MSG and Exchange respectively

Scroll down to select the email workload.

Email Workload Selection to Upload MSG in Exchange

On the Source Screen browse for the MSG files and Validate.

MSG files validated

Likewise, on the Destination Server add the admin credential on whose behalf the transfer is happening and Validate.

Validate Credentials for Exchange Server Prior to MSG Import

Then on the User mapping screen, fetch users, import a CSV, or Download a template fill it, and reupload the resultant file.

User Options to Import MSG in Exchange

A user Preview Screen opens here to mark the users for whom the MSG transfer is essential. Critical users apply the Exchange server endpoint and Validate.

After this press the Start Import button to begin the operation.

Start Import of MSG to Exchange

Best Practices to Follow While Importing MSG File to Microsoft Exchange Server

These practices are valid irrespective of the route you choose:

Keep a backup copy of all MSG files. Despite the top-rated security of all the methods described here none of them are 100% foolproof. Not to mention errors from the user end are far too common. So it is important to have a secondary file in case something goes wrong with the primary one.

Keep your endpoints ready and perform validation checks. Do this at regular intervals especially when dealing with a large number of files. Validation in the context of MSG to the Exchange Server import means to see whether or not the files that appear in the on-premise server are in the correct mailbox and format.

Schedule a test run before the main data transfer. This helps to determine if the pipelines arrangement is correct or not. Moreover, admins can use this to fix any errors. You dont need to put your actual user data at risk instead leverage AI to form a synthetic import scenario.

Conclusion

In this guide, we helped admins end the long-troubling problem of how to migrate MSG files to Microsoft Exchange Server. They can use multiple strategies to carry out the task from using Outlook client to applying Powershell scripts. However, none of them is as effective as using the automated tool prescribed above. So to save time and effort admins can move all orphan MSG files to the Exchange enclosure via the software.

Connect With Us

+9111-28084986