Messages Stuck in ‘Defunct’ SMTP Queue

I have a customer that recently experienced a SAN failure which corrupted multiple datastores that held their Virtual Machine hard drives. They were able to get all Exchange VMs up with the exception of one mailbox server. This server held two database copies from their production DAG. One was already mounted on a different server, however the second database was not. We were not able to get this database up, no matter the Powershell command for moving the active database nor the override settings either.
The repair process was as follows:

  • Created a new database, specifying the edb file name for the ‘defunct’ database and did not mount the database.
  • Copied the files from the ‘defunct’ database to this new directory.
  • Ran a soft recovery to replay logs.
  • Checked the database and its now in a clean shutdown state – eseutil /mh

Once the database was mounted we need to ‘re-home’ the mailboxes using a feature called database portability:

A simple Powershell command is all we need to re-home the mailboxes:

  • Get-Mailbox -Database db02 |where {$_.ObjectClass -NotMatch ‘(SystemAttendantMailbox|ExOleDbSystemMailbox)’}| Set-Mailbox -Database db02-new

Once all the mailboxes are re-homed to the new database any emails that were bound for the mailboxes while they were in the old store are now stuck in a queue specific to that database. The solution is to do the following:

  1. Suspend messages in the queue
  2. Export the messages to EML files
  3. Put these into the pickup folder of a Hub Transport server
  4. Wait for the pickup directory to be empty and delete any BAD emails
  5. Delete the messages in the queue.

Suspend Messages
First we need to know the name of the message queue. To do this we need to open up the queue viewer which is located in the Exchange System Console under Toolbox:

Once we have the Queue Viewer up, look for the queue for the database that is hung going to the defunct database:

Double click on that queue and get a properties of one message in the queue:

Notice the circled area in the message properties. That sequence is as follows server:

First we need to suspend all of the messages in the queue:

Exporting emails
We can now use PowerShell to export the emails. First we need a complete list of messageids which is the unique property for each message we need to export:

get-message -queue \ -resultsize unlimited | ft messageidentity

From this list we can build a series of commands to make this easier. This can be done either using a PowerShell script using arrays or and Excel spreadsheet. In my case this was a one off and I knew that I could fix this faster using Excel. Here is how to do it:

‘export-message -identity’ | assemblemessage -path “c:\temp\.eml”

Put these into the pickup folder of a Hub Transport server
Now that all the messages have been exported to EML files, open up a Windows Explorer window to copy the files from the ‘C:\temp’ directory (or wherever you placed them) to the Pickup folder for an Exchange 2010 Hub Transport server. This folder is typically in the ‘C:\Program Files\Microsoft\Exchange Server\V14\TransportRoles\Pickup’ directory. Once the files are copied there then they will be delivered to the mailboxes in the new mailbox database.

Delete BAD Emails
Once all the EML files are process and BAD emails are left behind you can delete these messages as they will not be delivered. Why would these messages be marked as BAD?

Badmail A message classified as badmail has serious problems that prevent the Pickup or Replay directories from submitting the message for delivery. The other condition that causes badmail is when the message is formatted correctly, but the recipients aren’t valid, and an NDR message can’t be sent to the sender because the sender isn’t valid.

Once this is completed you can remove the messages in the original queue. All future emails will go to the correct database now.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s