Migrating from POP3/SMTP servers using the M Drive


Exchange 2003 can be a great productivity booster for companies migrating from plain old SMTP/POP3 server. Group Calendaring and Public Folders suddenly transform the way a company works. I’ve seen it happen since the early days of Exchange.


However, migration a large company can sometimes be a slow and costly process. You have to send an army of field technicians to install and/or configure Outlook clients. You must import old PST files and sometimes convert local mail folders from varied mail clients.


One of the main issues when migrating POP3/SMTP servers is that mail delivery cannot be interrupted because people today rely on their e-mail for business use. So how do you perform the magic of seamless migration?


For many years, especially during the early migrations from UNIX to Exchange, mail would first arrive to our UNIX mail server. A technician would arrive at the user’s computer, complete the migration and then our UNIX guy would forward the users’ e-mail to the Exchange mailbox. This involves the use of sub-domains and maintaining a per-user list. It also meant that somebody had to be there at all times to help the technicians finish the job, so the UNIX guys (already not really happy that their precious e-mail system was taken away from them) would have to sit grumpy at the office all day, answering calls even if they were doing some other important stuff. Since the job involved manual editing of text files and grumpy UNIX guys sometimes this led some errors. Only after all the mailboxes were on Exchange the mail would flow directly to Exchange. This would take sometime as some of the users were out of the country, flying around the world, selling company products, some on vacation and so forth.


During another complex migration from a generic POP3/SMTP server I discovered a new way for performing this migration. Most of these servers store mail items as text files formatted using SMTP RFCs. Exchange 2000/3 can expose the mailbox store as folders containing EML files (this is called IFS of Installable File System). These files are the same in content as those commonly found in legacy mail server queues. This IFS drive, usually mapped as Drive M, is usually disabled these days so that antivirus software would not try to eat up its contents. However, during migration, I argued, it could be a useful tool.


What I proposed was not to wait until migration is over to change the mail flow order. Instead, Exchange will receive the mail instead of the POP3/SMTP server immediately after the empty mailboxes are created for the users. This will be done by switching the IP address between the two servers and maybe changing the internal DNS entry for the mail server.


So, after switching non-migrated users simply can read e-mails using POP3 off the brand new Exchange server (that is assuming POP3 is enabled). In case you can’t migrate passwords to Active Directory from your mail server, you can inform the users in advance of the change and use regular help desk assistance to help some users with their new password.


The problem is what to do with e-mails already in the queue of the old mail server. Basically what can be done is simply copy them to the new Exchange server.


First, enable the M: IFS Drive if it is not enabled by creating the following registry subkey if it does not exist:  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EXIFS\Parameters\DriveLetter. Enter “M” as the value of this subkey. Then restart the Microsoft Exchange Information Store service. In case of Exchange 2000 you might have to restart the server.




Now you can copy the queue locally or map a drive to the folder containing the old mail queue. If it’s a non-Microsoft server you might have to download the files using FTP.


Many mail servers keep the files serialized in a format so a typical file would be name something like this: “B000234234.MSG”. The M: Drive on the other hand exposes the files in the format [mail subject].EML. Although this is done mostly for convenience of browsing the mail items through Windows Explorer and Outlook doesn’t really care what the file name is, I have written some VBScript  code to adapt the old filenames before copying them.


The main body of my script looks like this:


dim fso, shell
set fso = CreateObject(“Scripting.FileSystemObject”)
Set shell = CreateObject(“Wscript.Shell”)
QueuePath = “D:\MailQueue”
MDrivePath = “M:\Domain.Test\MBX\”
      Set QueueMainFolder = fso.GetFolder(QueuePath)
      Set QueueFolders = QueueMainFolder.SubFolders
For Each Folder In QueueFolders
      Call ExportToMDrive(Folder)
Next ‘Folder


set fso = nothing
set shell = nothing
wscript.quit


The main code defines the path to the POP3 mailbox queue and the path to the mailboxes in the M: Drive. And then runs the ExportToMDrive subroutine on the all the folders in the queue.


Sub ExportToMDrive(UserQueue)
            Set fc = UserQueue.Files
            strUser = UserQueue.Name
            ‘Copy every file to the M drive
            For Each f1 in fc
                        if right(UCase(f1.name), 4) = “.MSG” Then
                                    Set ftext = fso.OpenTextFile (f1.path,1,-1)
                                    contents = ftext.ReadAll
                                    ArContents = Split (contents, chr(13))
                                    For I = 0 To UBound (ArContents) – 1
                                                line = ArContents (i)
                                                If InStr (line, “Subject:”) = 2 Then
                                                            strSubject = Trim(Mid(line,10))
                                                            If strSubject = “” Then 
                                                                        strSubject = “No Subject “
                                                            Else
                                                                        strSubject = ReplaceFileChars (strSubject)
                                                            End If     
                                                            J = 1
                                                            strSubjectTemp = strSubject
                                                            While fso.FileExists (MDrivePath & strUser & “\Inbox\” & _ 
                                                                                    strSubject & “.EML”)
                                                                        J = J + 1
                                                                        strSubject = strSubjectTemp & “-“& CStr (J)
                                                            Wend  
                                                            FN = MDrivePath & strUser & “\Inbox\” & strSubject & “.EML”
                                                            Set EMLFile = fso.CreateTextFile(FN, True)
                                                            EMLFile.Write contents
                                                            Exit For
                                                End If
                                    Next
                        End if
            Next
End Sub


What this sub does is rename each file so that it fits the subject of the mail items plus the “EML” extension and then copies it to the user’s Inbox folder. The code might need some modifications if another folder is used instead of “Inbox” for incoming mail. This might happen if you use a localized version of Outlook.


The subroutine appends a hyphen and a number to the filename if a file with the same name exists. This might happen if you have two mail items with the same subject.


The sub also uses the ReplaceFileChars Function that I’ve written to replace illegal characters with their equivalents the same was Exchange does.


Function ReplaceFileChars (strFileName)
Dim S 
    S = strFileName
    S = Replace (S,”%”,”%25″) 
    S = Replace (S,”*”,”%2A”) 
    S = Replace (S,”?”,”%3F”) 
    S = Replace (S,”/”,”_xf8ff_”)
    S = Replace (S,”:”,”%3A”)
    S = Replace (S,”|”,”%7C”)
    S = Replace (S,”\”,”_xf8fe_”)
    S = Replace (S,”>”,”%3C”)
    S = Replace (S, “\”,”%3E”)
    ReplaceFileChars = S
End Function


After transferring the files using the code most of the Outlook clients in the organization are using POP3 but now you can really take your time in converting them to work with MAPI to get the extra benefits that Exchange provides.


You can use this code free of charge, if it can help you to eliminate the hassle of migrating from legacy systems. You don’t really need much knowledge of coding to adapt it to your environment though it is definitely recommended to test it in the lab beforehand. If you find any bugs you can e-mail them to me at: [email protected].


Enjoy a smooth and carefree migration!

Leave a Comment

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top