How can email be resent that has been delivered to the Badmail folder in IIS?

Solution 1:

According to Microsoft support:

To replay the messages that are located in the Badmail folder, follow these steps:

  1. Stop the SMTP service.

    1. Open IIS Manager.

    2. Right-click Default SMTP Virtual Server, and then click Stop.

  2. Copy all the files that are located in the Badmail folder and that have the .bad file name extension. Then, paste these files to the Pickup folder.

  3. Delete the .bad file name extension from all the .bad files that are located in the Pickup folder.

  4. Start the SMTP service.

    1. Open IIS Manager.

    2. Right-click Default SMTP Virtual Server, and then click Start.

  5. Verify that the messages were delivered.

Solution 2:

Create a batch file.

@Echo on 
net stop smtpsvc
move x:\inetpub\mailroot\badmail\\*.bad x:\inetpub\mailroot\pickup\\*.
cd\
net start smtpsvc

Solution 3:

Alternatively, you could use the Powershell script below wonderfully created by our in-house technical guru. It drops the "Delivery Failure" part of the .BAD file and retries the message as if it were the original send.

$INETPUBHome = "C:\inetpub\mailroot"
$BadMail = "$INETPUBHome\BadMail"
$Pickup = "$INETPUBHome\Pickup"

stop-service -Name SMTPSVC

foreach ($f in Get-ChildItem -Path $BadMail -Filter *.bad) {
    $smpt_body = Get-Content -Path $f.FullName -Raw

    $r = $smpt_body -replace "(?smi)From:[^!]+?^From:", "From:"

    $r | Out-File -FilePath $Pickup\$($f.BaseName) -Encoding ascii

    Remove-Item $f.FullName
}

start-service -Name SMTPSVC