How do I set up smtp on Vista so I can use System.Net.Mail?

北战南征 提交于 2019-12-04 03:21:30

As you know SMTP no longer ships with Vista (Which is one of my biggest complaints about Vista). As you already know there are many options out there, and if you found a good free one post a link to it. How you configure it will probally depend on the server you install.

I played around with some trial smtp servers, and all the ones I used started listening on the standard SMTP ports on the loopback IP Address. I believe this is the default MailSettings, and shouldn't require any changes.

I no longer have any SMTP server and am using the Pickup Directory mode. This causes the mail library to output a file which I can then inspect.

To configure this use the following in your config file:

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

If you want to configure it to connect to port 25 on your local host you would this for the SMTP section:

<smtp deliveryMethod="Network">
   <network defaultCredentials="true" host="localhost" port="25"/>
</smtp>

Edit

Terry asked a good question about using the drop location. I only use this for testing, as our production server has an SMTP server which I connect to, and send the email through; however, some SMTP servers can be configured to watch a directory and will pick up and mail anything in there.

I don't think this feature was meant to be used only for testing but it works nicely. The files that get generated can be opened in various mail clients so you can see how they would render them. I belive they .eml files but I can't remember.

You can find a very basic SMTP server coded in C# .NET in stickymailserver:

Sticky Mail Server is a low-interaction SMTP Honeypot designed to emulate a open SMTP relay. It captures and logs probe messages and mass mailings and saves them for later analysis.

You could use an externally hosted SMTP server. I have found that a lot of email system will block access if the originating SMTP server is behind a dynamic IP address (like most residential systems).

I had to do this recently.

 SmtpClient smtp = new SmtpClient("smtp.myserver.com");
 smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
 smtp.Credentials = new System.Net.NetworkCredential("Username", "Password");

Using the "SendCompleted" event, you can send the email in the background without delaying the application.

gangelo

@JoshBerke

I've tried using the below option but receive "Cannot get IIS pickup directory". I know I am pointing to an existing directory, are there permissions I need to set up on the directory?

<smtp deliveryMethod="SpecifiedPickupDirectory">
     <specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop"/>
</smtp>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!