Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


March 2002

Sending Email from IIS

RSS
Subscribe to Windows Web Solutions | See More Scripting Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

Use the SMTP service to send email messages from your Web server

Despite the explosion of Web sites available on the Internet, email is still the most widely used Internet service. You can easily configure your IIS machines to send email messages over the Internet or through intranets. To do so, you need the Microsoft SMTP Service. I show you how to configure the SMTP service, includ-ing some advanced parameters, and provide a few downloadable code samples that you can leverage in your environments.

Getting SMTP Up and Running
If you haven't used the SMTP service before, it must be running on your Web server. The SMTP service is part of the default IIS installation. If you performed a custom IIS 5.0 or IIS 4.0 installation and chose not to install the service, you can easily add it from the Control Panel Add/Remove Programs applet. To do so, open the Add/Remove Programs applet, click Add/Remove Windows Components, select the Internet Information Services check box, then click Details.

In a default IIS installation, one SMTP server is installed. You can verify that it's running by opening Internet Services Manager (ISM) and viewing the SMTP server. FTP sites appear first, followed by Web sites and SMTP sites. If the SMTP server isn't running, right-click it, then select Start.

Advanced Configuration
Now, let's look at a few of the advanced configuration options. Most large or enterprise companies place SMTP servers behind firewalls that block any direct outbound SMTP traffic through port 25. If such is the case in your shop, your email messages will end up in the Badmail folder with cryptic router error-message files. If a smart host is available on your network, you can use it to relay all SMTP messages to the Internet.

In most cases, a smart host is simply another SMTP server with permission to relay outgoing email messages from other internal SMTP servers directly to the Internet. Thus, a smart host should be able to connect simultaneously to both the internal network and the Internet to work as the email gateway. If this setup exists in your company, you can simply add the IP address of the smart host on your network and IIS will send its email messages to that SMTP server for relay to the Internet. To set up a relay to a smart host on an IIS 5.0 or IIS 4.0 machine, follow these steps:

  1. Open ISM, right-click the SMTP server, then select Properties.
  2. Click the Delivery tab, then click Advanced to open the Advanced Delivery dialog box, which Figure 1 shows.
  3. In the Smart host field, type either the smart host's Fully Qualified Domain Name (FQDN) or its IP address surrounded by square brackets (e.g., [10.1.4.25]). The brackets help speed up the DNS lookup process by specifically telling the SMTP server that the numbers are an IP address. Click OK twice to complete the changes.

In the Advanced Delivery dialog box, notice the Masquerade domain field. The masquerade domain makes an email message look as though it came from a point other than its true origin. You can easily fake return addresses on email messages. For example, if I enter

HuckabyIISParadise.com

in the Masquerade domain field, mail messages would appear to come from addresses such as tim@huckabyiis paradise.com. Obviously, the practical joke potential is spectacular here, but be forewarned: Configuring POP3 mail servers to check the domain before accepting an email message is equally easy.

Sending Mail Simply with CDONTS
With your SMTP server configured, you're ready for a simple test using Collaboration Data Objects for Windows NT Server. CDONTS is a set of COM components that's installed with IIS and exposes messaging objects to languages such as VBScript in Active Server Pages (ASP) applications. CDONTS has a simple object called NewMail that lets you send email messages from IIS with only a few lines of code. (I show you the inner workings of the CDONTS NewMail object in the next section.) In the simplest implementation of this object, you need only the few lines of code that Listing 1 shows.

Create a sample folder in your test IIS Web server's file system called \inetpub\wwwroot\smtp. Then, download smtp-cdonts.asp from the Code Library on the Windows Web Solutions Web site (http://www.windowswebsolutions.com) and place the file in the sample folder. Run your favorite editor (e.g., Microsoft Visual InterDev, Notepad) and edit the From, To, Subject, and Message Content parameters appropriately. (You'll probably want to send messages to yourself while testing.) Save the file. Next, open a browser and navigate to smtp-cdonts.asp. IIS will send an email message from your SMTP server.

To properly deliver email messages, you need Internet connectivity from your server. If you don't have Internet access, verifying that the SMTP server is sending email messages is easy because the email messages' file images are dropped into the queue in \inetpub\mailroot\queue. You can use any email client (e.g., Microsoft Outlook Express) to view these files. If anything is wrong in a message's addressing, the SMTP server moves the email message to \inetpub\mailroot\badmail.

   Previous  [1]  2  3  Next 


Reader Comments
hello

tauseef December 22, 2003


An additional article that helped make all this work for me was: http://support.microsoft.com/default.aspx?scid=kb;en-us;310336&Product=iis50

Minkah January 15, 2004


Is there any way to send email on a particular date to some mail ids without opening any web pages. Automatically it should send emails without user interaction not even opening the web site or any other web pages

Jane Carol April 30, 2004


Tim: I'v done the installation, and can receive emails, but cannot send them from the server. I get error message 550: One of the recipients was rejected by the server. The rejected email address was ....This happens for all email addresses that I have tried. I would appreciate any suggestions that you may have.

Hank Loos May 10, 2004


v

Anonymous User November 08, 2004


With that done. My real query was, I have a domain (www.mydomain.net) how can i set up my IIS server to host email for this domain without paying a company such as yahoo to add email to my domain registration?

Anonymous User January 19, 2005 (Article Rating: )


You will need to have your ISP (or whoever hosts your DNS) add an MX record for the Internet address of your mail server.

Anonymous User June 30, 2005 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
The Memory-Optimization Hoax

Don't believe the hype. At best, RAM optimizers have no effect. At worst, they seriously degrade performance. ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 24, 2008

An often irreverent look at some of the week's other news, including a Vista Capable dismissal request, Zune price reductions, Morrow musings, Novell and Microsoft sitting in a tree ... two years later, Yahoo!, IE 6 on Windows Mobile, and so much more ...


Related Events Delivering Reliable and Effective Web-Based Applications

Making Web Application Perform Better: What to Watch, How to Watch It, and How to Fix It

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing