IIS SMTP Email Stuck in mailroot/Queue: Troubleshooting and Solutions


1 views

When IIS SMTP service fails to deliver emails from the pickup directory, messages accumulate in mailroot\Queue without being processed. This common issue typically stems from configuration problems rather than code errors.

First verify basic SMTP functionality:

telnet your.smtp.server 25
HELO test
MAIL FROM: test@domain.com
RCPT TO: valid@recipient.com
DATA
Test message
.
QUIT

If this fails, your SMTP service isn't properly accepting connections. Check these key areas:

In IIS 6.0 Manager (or equivalent):

1. Verify "Smart host" setting in Delivery tab
2. Check "Outbound Security" credentials
3. Confirm "Outbound connections" port 25
4. Validate DNS resolution settings

The SMTP service account needs:

icacls C:\inetpub\mailroot\Queue /grant "NETWORK SERVICE":(OI)(CI)F
icacls C:\inetpub\mailroot\Pickup /grant "NETWORK SERVICE":(OI)(CI)F

Test if your server allows relaying:

// PowerShell test
Test-NetConnection -ComputerName your.smtp.server -Port 25
$smtp = New-Object Net.Mail.SmtpClient("your.smtp.server")
$smtp.Send("from@domain.com","to@domain.com","Test","Test body")

Enable SMTP logging:

1. IIS Manager → SMTP Virtual Server → Properties → Enable logging
2. Set log format to "W3C Extended Log File Format"
3. Review log at C:\WINDOWS\system32\LogFiles\SMTPSVC1

For ASP.NET applications, ensure proper configuration:

<system.net>
  <mailSettings>
    <smtp deliveryMethod="SpecifiedPickupDirectory">
      <specifiedPickupDirectory pickupDirectoryLocation="C:\inetpub\mailroot\Pickup"/>
      <network host="your.smtp.server" port="25"/>
    </smtp>
  </mailSettings>
</system.net>

If using custom service accounts:

sc config SMTPSVC obj= "DOMAIN\Account" password= "password"

When emails get stuck in the IIS mailroot/Queue directory, it typically indicates a breakdown in the SMTP delivery chain. Here's what's happening behind the scenes:

// Sample path where emails get stuck
C:\inetpub\mailroot\Queue\*.eml

Authentication Issues: The SMTP service might lack proper credentials for relaying.

DNS Resolution Failures: Inability to resolve recipient domains.

Port Blocking: Firewalls blocking port 25 (SMTP) outbound traffic.

Smart Host Misconfiguration: Missing or incorrect smart host settings.

1. Check SMTP virtual server status:
   net start SMTPSVC

2. Verify DNS settings:
   nslookup -type=MX targetdomain.com

3. Test port connectivity:
   telnet mail.server.com 25

Smart Host Setup:

// Metabase configuration example
adsutil.vbs set smtpsvc/1/SmartHost "smtp.provider.com"
adsutil.vbs set smtpsvc/1/SmartHostType 1

Authentication Configuration:

// Configure basic authentication
adsutil.vbs set smtpsvc/1/RootDropDir "C:\inetpub\mailroot"
adsutil.vbs set smtpsvc/1/AuthenticationPackages "NTLM"

Enable SMTP logging (in %windir%\system32\logfiles\smtpsvc1) and check:

  • Event ID 4009 - Message queued for delivery
  • Event ID 4011 - Message delivered
  • Event ID 4003 - Delivery failed
@echo off
:: Script to monitor and restart SMTP service if queue builds up
set queue_path=C:\inetpub\mailroot\Queue
set max_files=10

for /f %%a in ('dir /b "%queue_path%\*.eml" ^| find /c /v ""') do set file_count=%%a

if %file_count% gtr %max_files% (
   net stop SMTPSVC
   net start SMTPSVC
)