Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

From what I understand there is no SMTP server in IIS on Vista. I am working on a project which will require me to send email. I'd like to start with some simple prototypes on my development box which is running Vista Ultimate. I'm not connected to a corporate network where I can just use an exchange server someplace.

I realize that there are several smtp servers that I can install, but I'm not sure what to do once I install one. I know how to write the code to send the email, but I don't know what kind of configuration needs to be done to use the smtp server.

What I'd like is a clear description of what to do once I get an smtp server installed on my Vista box.

Thanks!

UPDATE: I downloaded this smtp server: http://softstack.com/freesmtp.html

Here's what my code looks like:

class Program
{
    static void Main(string[] args)
    {
        MailMessage message = new MailMessage();    
        message.From = new MailAddress("[email protected]");    
        message.To.Add(new MailAddress("[email protected]"));               
        //message.To.Add(new MailAddress("[email protected]"));    
        //message.CC.Add(new MailAddress("[email protected]"));    
        message.Subject = "This is my subject";    
        message.Body = "This is the content";    
        SmtpClient client = new SmtpClient("localhost");    
        client.Send(message);    
        Console.ReadLine();     
    }
}

When I have this smtp server running and I execute my console app, it hands on the client.send line. The smtp server looks like this:

http://screencast.com/t/2B7jv0bE14

After a while the client.send times out.

Any ideas what's going wrong now?

Thanks!

like image 960
Tad Donaghe Avatar asked Mar 31 '09 16:03

Tad Donaghe


People also ask

What is System Net mail?

Allows applications to send email by using the Simple Mail Transfer Protocol (SMTP). The SmtpClient type is obsolete on some platforms and not recommended on others; for more information, see the Remarks section.

Can I use different SMTP server for sending mail?

You can send messages via multiple SMTP servers for various reasons. First, to improve reliability (if the main server is down, sending may still succeed via the backup server).

Is SMTP server part of email settings?

SMTP settings are simply your outgoing mail server settings; this particular protocol only works for outgoing messages. Most email software is designed to use SMTP for communication purposes when sending email.


1 Answers

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.

like image 68
JoshBerke Avatar answered Nov 01 '22 12:11

JoshBerke