Other properties of MailMessage that you may need to use include
AlternateViews, BodyEncoding, DeliveryNotificationOptions, Headers,
Priority, ReplyTo, Sender, and SubjectEncoding.
The From field has the MailAddress type, representing an email address. The To,
CC, and Bcc properties are of the MailAddressCollection type, representing a
collection of MailAddress objects.
As you can see, there are lots of classes and properties that let you define email
messages. However, to be able to send these messages, you need access to a SMTP
server.
The standard email protocol of the Internet is Simple Mail Transfer Protocol
(SMTP). When you use ASP.NET to send an email, the message is relayed
through one or more SMTP servers on the way to its final destination. Most ISPs
provide an SMTP server for customers use; alternatively, if youre using IIS, you
can make use of Windows built-in SMTP Server.
Configuring the SMTP Server
IIS Only
If youre not using IIS, or you have access to an external SMTP server, you
can choose to skip this section.
In order to send an email, you need to connect to an SMTP server. On Windows,
an SMTP server is included with IIS, and youll need to configure this server if
you want to send email from ASP.NET. First, you need to make sure that the
SMTP service is running. Open the IIS applet to check its status. If the server is
stopped, you can right-click its icon and select Start to start it, as shown in Fig-
ure 14.13.
If the SMTP server entry doesnt appear, youll need to install it using the process
outlined below. Note that the SMTP server is a component of IIS, so if you
havent installed IIS (or if your Windows version doesnt support IIS, as is the
case with Windows XP Home) you wont be able to install the SMTP server.
1.
Launch the Add or Remove Programs applet in Control Panel.
2.
Click Add/Remove Windows Components.
3.
Select the Internet Information Services item, and click Details.
595
Configuring the SMTP Server
Figure 14.13. Starting the SMTP Virtual Server
4.
Select SMTP Service.
5.
Click OK, then Next.
6. Run the Internet Information Services utility again. This time, you should
see the SMTP service running.
Now that you have a running SMTP server, you need to configure it. In order
for email to be relayed correctly, perform the following steps:
1. Open the Internet Information Services utility.
2.
Right-click Default SMTP Virtual Server and choose Properties.
3.
Select the Access tab.
4.
Click Relay.
5.
Click the Add button.
6. Add the localhost IP address: 127.0.0.1.
7.
Uncheck the Allow all computers checkbox. The dialog should look similar
to Figure 14.14.
596
Chapter 14: Working with Files and Email

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.