8

We have IIS setup as an SMTP relay. A relay security error caused the outbound emails to be dropped to the badmail folder for the IIS SMTP Service.

Is there any standard method for attempting to retry delivery of these emails?

SamErde
  • 3,409
  • 3
  • 24
  • 44
catalpa
  • 321
  • 1
  • 2
  • 9
  • 3
    I create a simples C# program to remove bad header and rename .BAD file to .EML It work for me. Maybe work too to someone. https://github.com/zogbi/BadToPickup –  Jul 30 '15 at 13:54

5 Answers5

14

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.

Michael
  • 239
  • 2
  • 10
catalpa
  • 321
  • 1
  • 2
  • 9
  • That MS KB article is apparently no longer available. Wonderful. – wfaulk Apr 12 '18 at 15:58
  • Note that this re-sends the delivery failure notification, not the original message. – Michael Jan 23 '20 at 19:26
  • You can edit the C:\inetpub\mailroot\Badmail\*.bad file to manually remove the delivery failure notification portion of the message as shown by Ashley's response below. Instead of PowerShell, open the file and look for the second "From:". Delete everything before but not including the second "From:" – Dacid Salin Mar 09 '20 at 16:24
6

Create a batch file.

@Echo on 
net stop smtpsvc
move x:\inetpub\mailroot\badmail\\*.bad x:\inetpub\mailroot\pickup\\*.
cd\
net start smtpsvc
kasperd
  • 30,455
  • 17
  • 76
  • 124
Salcolen
  • 61
  • 1
  • 1
6

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
Michael
  • 239
  • 2
  • 10
Ashley Ward
  • 61
  • 1
  • 1
-1

You can open a command prompt and navigate to the badmail folder and run the following command to remove extensions on all messages:

rename *.* *.

Viktor
  • 1
  • This comment is missing the movement of the file to the correct folder to resend the message. – Dacid Salin Mar 09 '20 at 16:26
  • This would have been a valid comment, but not a valid answer. Also... the command should be "rename *.bad *." so it doesn't strip the extension from .nbr files. – SamErde Mar 31 '20 at 18:11
-2

Drag and drop them in the pickup folder.

SBWorks
  • 289
  • 1
  • 3
  • 12