Vista and an SMTP Server on port 25 or 587

I was answering a post in the newsgroups about a developer wanting to run IIS SMTP on Vista.  This feature is NOT included in Vista.  The person was frustrated they couldn’t test their email code.  This post is meant to provide a couple examples tested on Vista Ultimate.  Here is a couple of tricks I did using FreeSMTP http://softstack.com/freesmtp.html.  The install is simple and the user interface is straight forward.   By default it has the port number and DNS server automatically configured.  Look in the picture one in the bottom of the window.


For your purposes as a developer, you want to verify your code works when sending emails.  To show you this works on Vista, I posted 2 code samples and the email headers from an ASP and ASP.NET 2.0 webpage. Vista does not have an SMTP service like they did in 2000, XP. Vista does support the ability to have your application forward emails to a remote host.  That is the one ‘feature’ in the IIS manager, this is NOT an SMTP server.  The FreeSMTP one is slick because it runs interactively.  Meaning  when it’s showing in the task bar, it works.

Another thing you can do to make sure your local SMTP server is working. Change the SMTP port to 587 and send yourself a test message to your Gmail account, assuming you one.  I was able to successfully test on an alternative port, assuming your ISP is blocking port 25.  Port 587 is a well-known alternative SMTP port.  Gmail accepts email on this port.  Here is my ASP code run on my Vista box.  I couldn’t figure out how to extract the email headers from my Gmail account, but the message did get there.  Hope this helps.


Free SMTP GUI



If your ISP blocks 25, you can adjust the port to 587, then test to your Gmail account.  Assuming you have one.  click File, Options close and open the program and you are good to go.



To verify your machine has port 25 or 587 open, go to the command prompt, type netstat -an -p tcp.  You should see 0.0.0.0:25 or 0.0.0.0:587



Test using port 587. 


<html>
<body>

<%
sch = “http://schemas.microsoft.com/cdo/configuration/

    Set cdoConfig = CreateObject(“CDO.Configuration”)

    With cdoConfig.Fields
        .Item(sch & “sendusing”) = 2 ‘ cdoSendUsingPort
        .Item(sch & “smtpserver”) = “127.0.0.1”
 .Item(sch & “smtpserverport”) = “587”
        .update
    End With

    Set cdoMessage = CreateObject(“CDO.Message”)

    With cdoMessage
        Set .Configuration = cdoConfig
        .From = “steve@example.com
        .To = “YourAccount@gmail.com
        .Subject = “Sample CDO Message”
        .TextBody = “This is a test for CDO.message”
        .Send
    End With

    Set cdoMessage = Nothing
    Set cdoConfig = Nothing
    response.write “Sent”
%>


</body>
</html>
 


Test using port 25


Here is my examples.

——————
ASP.NET 2.0 page
——————
<html>
 <body>
 <%

‘create the mail message
Dim mail As New System.Net.Mail.MailMessage()

‘set the addresses
mail.From = New System.Net.Mail.MailAddress(“steve@example.com“)
mail.To.Add(“steve@example.com“)

‘set the content
mail.Subject = “This is an email”
mail.Body = “this is the body content of the email.”

‘send the message
Dim smtp As New System.Net.Mail.SmtpClient(“127.0.0.1”)
smtp.Send(mail)
 %>

 </body>
</html>

——————
ASP.NET 2.0 page email headers.
——————


Notice the ‘Received’ line where it says received from pc1.aspdot.net to mail.example.com, this is my local Vista box send to an external mail server.  The only thing I changed was the ‘example’ word. 

Return-Path: <steve@example.com>
Received: from pc1.aspdot.net [192.168.0.90] by mail.example.com with SMTP;
   Fri, 7 Sep 2007 07:31:57 -0400
mime-version: 1.0
from: steve@example.com
to: steve@example.com
date: 7 Sep 2007 07:31:57 -0400
subject: This is an email
content-type: text/plain; charset=us-ascii
content-transfer-encoding: quoted-printable

this is the body content of the email.

——————
Classic ASP example
——————-
<html>
<body>

<%
sch = “http://schemas.microsoft.com/cdo/configuration/

    Set cdoConfig = CreateObject(“CDO.Configuration”)

    With cdoConfig.Fields
        .Item(sch & “sendusing”) = 2 ‘ cdoSendUsingPort
        .Item(sch & “smtpserver”) = “127.0.0.1”
        .update
    End With

    Set cdoMessage = CreateObject(“CDO.Message”)

    With cdoMessage
        Set .Configuration = cdoConfig
        .From = “steve@example.com
        .To = “steve@example.com
        .Subject = “Sample CDO Message”
        .TextBody = “This is a test for CDO.message”
        .Send
    End With

    Set cdoMessage = Nothing
    Set cdoConfig = Nothing
    response.write “Sent”
%>

</body>
</html>

——————
Classic CDOSYS email headers using cdosys
——————

Again, notice the ‘Received’ line where it says received from pc1.aspdot.net to mail.example.com, this is my local Vista box sending to an external mail server.

Return-Path: <steve@example.com>
Received: from pc1.aspdot.net [192.168.0.90] by mail.example.com with SMTP;
   Fri, 7 Sep 2007 07:26:21 -0400
thread-index: AcfxQerDubACV5L/Q2aEgBOgiPw2rQ==
Thread-Topic: Sample CDO Message
From: <steve@example.com>
To: <steve@example.com>
Subject: Sample CDO Message
Date: Fri, 7 Sep 2007 07:26:21 -0400
Message-ID: <D7FBFDDB5A87496F9A7645E782A144DE@aspdot.net>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16480

This is a test for CDO.message
 


Thanks to www.aspfaq.com and www.systemnetmail.com for assistance on the code samples.


Steve Schofield
Microsoft MVP – IIS

5 thoughts on “Vista and an SMTP Server on port 25 or 587”

  1. Why not just dump the email to the file system? This is configurable through the web.config – plus you can open the email through Outlook Express (Windows Mail)

    Like

  2. I was not aware this was possible. Do you have a link that explains this concept further. In most of my experience, a developer wants to test the application locally and have it simulate a production environment, this includes email. However, if that is controlled in the web.config, that is a handy method.

    Like

  3. Took a bit of digging – but check here for a sample:

    http://weblogs.asp.net/dfindley/archive/2006/04/23/Migrating-from-System.Web.Mail-to-System.Net.Mail.aspx

    In .Net 2.0 – you get to select the SMTP delivery method. So – in this case, you would set it to SpecifiedPickupDirectory.

    I agree with how developers should try to simulate live environments as much as possible. However – sometimes things are out of our control. The network may block a port, or you may be on Vista which doesn’t include the virtual SMTP server 2000 & XP does.

    Hope this helps you out!

    – Ron

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s