Question

If I've queued up some email to be sent via the System.Net.Mail.SMTPClent, where can I find this mail? With the Windows SMTP Client, it's in the C:\inetpub\mailroot folder - is there a similar folder for the .NET client?

EDIT: Here's an example. If I turn off the outgoing SMTP server on my XP computer and then run an application that sends a dozen emails, they get queued up somewhere, since the .NET SMTPClient.Send call succeeds. A few hours later, I start the local SMTP server, and the mail leaves in a sudden flurry. Where is it in the meantime? The same behavior happens on my Vista desktop, though I have no local SMTP server - I can duplicate the functionality by blocking port 25 on the firewall, and then mail queues up somewhere. Where?

The reason for this question is that I want to re-enable the SMTP Service on a server I have, but I don't know what's been queued up in the meantime, and I want to make sure the queue is clean when I re-enable the service. That way, customers don't get really, really old queued emails all of the sudden.

EDIT: Clearly, I don't know what I'm talking about. When I do this on Vista:

    Dim mm As New System.Net.Mail.MailMessage("me@me.com", "you@you.com", "Testing", "this is a test")

    Dim s As New System.Net.Mail.SmtpClient("localhost")
    s.DeliveryMethod = Mail.SmtpDeliveryMethod.PickupDirectoryFromIis
    s.Send(mm)

I get an exception because I don't have an IIS pickup folder. Changing it to "Mail.SmtpDeliveryMethod.Network" results in an immediate exception because I don't have an SMTP server running. I'll test this on server 2003, but I could have sworn that these both worked in the past. I'll do some more testing and modify the question if needed.

Was it helpful?

Solution

From the looks of the MSDN pages for SmtpClient, it's configurable. You can use the DeliveryMethod property to decide whether mail is sent immediately, whether it's queued into the IIS pickup folder (presumably C:\inetpub\mailroot) or whether it's placed in a folder of your choosing (specified by the PickupDirectoryLocation property).

OTHER TIPS

The description is a little vague, but if you call Send() and your DeliveryMethod is Network and the call succeeds, then it's not in the realm of .NET anymore. Something has accepted it for delivery and it is sitting in that something's queue, which jumps for joy when you turn on the mail server that can connect with the outside world back on. When DeliveryMethod is Network, I'm pretty sure (at least, judging from the Reflector disassembly) that it's scribbling directly on a network stream and not via some intermediate temp file. If it couldn't open a connection and get that stream, then it vomits with an exception. This coincides with my actual experience in using this class. Hope that helps.

By default the SMTP client uses a network sending. So no emails are stored anywhere.

Here is the configuration section of the web.config

        <mailSettings>
        <!--
            <smtp
                deliveryMethod = "Network" [Network | SpecifiedPickupDirectory | PickupDirectoryFromIis]
                from = "" [String]
                >
                <network
                    defaultCredentials = "false" [true|false]
                    host = "" [String]
                    password = "" [String]
                    port = "25" [number]
                    userName = "" [String]
                />
                <specifiedPickupDirectory
                    pickupDirectoryLocation = "" [String]
                />
            </smtp>
        -->
        <smtp deliveryMethod="Network">
            <network defaultCredentials="false" port="25" />
        </smtp>
    </mailSettings>

You can take a look to this article in code project which shows how to handle manually the files created by the SMTP Client when DeliveryMethod == SmtpDeliveryMethod.SpecifiedPickupDirectory.

You can set the specified pickup directory and delivery method for greater control

<system.net>
    <mailSettings>
        <smtp deliveryMethod="SpecifiedPickupDirectory">
            <specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\" />
        </smtp>
    </mailSettings>
</sysetm.net>

The .NET SMTP client I'm used to doesn't store mail anywhere. It just sends. If the outbound server it is supposed to send through is down, it gives an exception immediately.

You've tried turning on and off the outbound server on your XP box. Great. Now, try to find the inbound SMTP service. The inbound and outbound SMTP services talk to each other by filedrop.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top