views:

1767

answers:

5

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("[email protected]", "[email protected]", "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.

+2  A: 

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).

Matt Hamilton
Now that you've edited your question I realise that I'm not really answering it. I guess your best bet is to specify the pickup directory manually so that you know where it is. I can't find any reference to its default location. %TEMP% maybe.
Matt Hamilton
You're on the right track now. Since I don't have a mailroot folder, sending my mail to the IIS pickup folder just sends it into the abyss (Crappy handling, Microsoft!), but I can specify the picup directory manually and see my mail. But I still want to know where the default folder is!
rwmnau
A: 

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.

Joshua
A: 

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.

labilbe
A: 

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.

Nicholas Piasecki
A: 

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>
RandomNoob