Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Tài liệu SMTP and POP3 doc
Nội dung xem thử
Mô tả chi tiết
5
SMTP and POP3: Communicating with
email Servers
5.1 Introduction
More emails are sent every day than postal mail. Why? Because email is
cheap, informal, fast, and can be picked up at the receiver’s convenience. Emails
can be automatically generated and sent, making them ideal for automated
status notification. One day, you may receive an email from your home sprinkler
system saying simply, “Your house is on fire.”
After reading this chapter you will be able to send and receive emails from your
.NET applications. These features can be useful for customer support systems,
collaborative personnel management, and many other types of applications.
This chapter begins by describing how emails can be constructed and sent, using
either a socket-level approach, or by using in-built .NET classes. Immediately
following that, is a description on how emails may be received, again, by either using
a socket level approach, or a higher-level methodol- ogy, leveraging Microsoft
Outlook.
5.2 Sending an email
Every email must have a destination email address. An email address takes
the following form:
<Username>@<domain name>
The domain name in an email address generally does not include the
“www” prefix, which is common for Web site addresses. Despite that, the domain
name is globally recognized under the DNS system. The username
is recognized only by the recipient mail server.
Emails are not immediately delivered to the recipient; instead, they are
initially sent to your ISP’s or company’s mail server. From there, they are forwarded
to the recipient’s mail server or held for a period of time until the recipient’s mail
server accepts the email. Emails are sent using the simple mail transfer protocol
(SMTP), which is described in detail later.
In order to determine the recipient’s mail server, a DNS mail exchange
(MX) query is issued to the local DNS server for that domain name. That computer
will then return details of where the server or servers that handle incoming mail are
located.
Note: Most ISPs have only one incoming mail server, but Hotmail.com has
more than 10 mail servers.
You will always be told the IP address of your SMTP server. Unfortunately, you cannot use an SMTP server from another ISP because it will block you
with an error message such as “Relaying denied.”
Microsoft virtual SMTP server is available for most versions of Win- dows and
generally appears under IIS when installed.
5.2 SMTP
SMTP is used to send, but not receive, emails. Every mail server in the
world must conform to the SMTP standard in order to send emails reli- ably
regardless of destination. The definitive guide to SMTP is held by the Internet
Engineering Task Force (IETF) under RFC 821 at www.ietf.org/ rfc/rfc0821.txt.
The definitive guides to most major protocols are held at the IETF. They
are free to download and should be consulted when you are develop- ing network
applications that are designed to work with preexisting or third-party clients or
servers.
SMTP is not a difficult protocol to implement from the ground up;
however, it is natively supported from .NET and, thus, would be a waste of time to
redevelop. Also, many commercial email components are available, which can be
imported into your application. One of the most popular is AspEmail from Persits
Software. The demo version of this component is adequate for most applications.
5.3.1 Implementing SMTP
SMTP operates on TCP port 25. Before sitting down to code, you should
first find out the IP address of your ISP’s SMTP server. In the examples below, the
SMTP server smtp.ntlworld.com is used. You should replace this with your
own SMTP server, or the examples will not work.
SMTP was originally designed for UNIX users and has a command- linetype feel to it, although the commands are issued over a network con- nection, rather
than a keyboard.
A good way to test the protocol is to open telnet by clicking Start→Run and type
telnet. In Windows NT, 2000, and XP, type o smtp.ntlworld.com 25. In prior versions of Windows, click File→Connect, and then
type smtp.ntlworld.com into the connection box and 25 into the port box.
Then press Connect.
Once the client establishes a TCP connection to the server on port 25, the server
will always reply with 220 <some greeting message><enter>. A number is
always included at the start of every server response. Any number beginning with 5 is
an error and should be dealt with; everything else can