A Primer in Internet Mail

Before you can unleash your programming skills on sending email with Perl, you need to know something about how mail works on the Internet.

Before Perl was born, when the Web wasn't even a twinkle in NCSA's eyes and modems were slow, people worldwide communicated using email over a system called UNIX-to-UNIX copy (UUCP). When you sent email under this old system, the local system bundled up your email and forwarded it to the next system in a chain, which bundled up the email and forwarded it on. Each system in the line added a little bit to the message, indicating that it handled the message and then passed it on, as illustrated in Figure 22.1.

Figure 22.1. Handing off mail from system to system.


This method of mail propagation is called store and forward, for obvious reasons. UUCP has since been replaced, but the basic method of store and forward still persists. When you send mail from your PC, another system picks up the mail and relays it to another system; that system then relays the mail again until the target system finally receives the mail.

The protocols have all changed, though. Most commonly, Simple Mail Transport Protocol (SMTP) is used to send mail out onto the chain (see Figure 22.2). To receive it, the target end of the connection usually uses either Post Office Protocol (POP) or Internet Message Access Protocol (IMAP). The part you're going to be concerned with for sending mail is SMTP.

Figure 22.2. Different protocols used in sending mail.


Sending a Mail Message

To send an email message, you need a couple of things: a Mail Transport Agent or an SMTP relay host.

Whoa. Sorry. Those were pretty heavy terms to drop, but I'll explain.

A Mail Transport Agent (MTA) is a program that resides on your computer—it usually comes with your operating system—and is in charge of taking email messages and forwarding them correctly. An MTA is usually already configured correctly when your operating system is installed. One common MTA on UNIX systems is called sendmail. The sendmail program takes a mail message and figures out how to deliver it to the destination.

To send a mail message under UNIX, at the command line you could use this syntax:

							$ /bin/echo "Subject:Test

Hello, World!" | sendmail [email protected]
						

The preceding snippet would send a short message to [email protected]. The sendmail program takes care of all the difficult parts for you: deciding which mail relay to use, handling bounced (refused) mail, and so on.

If you're using a Microsoft Windows or a Macintosh operating system, you don't have a built-in MTA. Fortunately, a Perl module enables you to send mail directly. The Net::SMTP module can send mail without an intervening MTA, but you have to know the name of your SMTP relay host. This name is the "Mail Host" hostname for sending mail that you were given when you signed up for your account. Get the name of the relay host, and write it down somewhere; you'll need it later.

Note

You may have different "Mail Hosts" for sending and receiving mail. For this hour you'll need the "sending" hostname.


Remember: Programs that rely on an SMTP relay need to have the correct relay host built in to the software, or the process will not work.

Caution

The correct "SMTP relay hostname" depends on where you're sending mail from. If you're sending mail from home, your home Internet service provider (ISP) account has given you an SMTP relay hostname. If you're sending mail from an account on a rented Web server, you need the name of the relay host for that server. Mail relays usually refuse mail when it's sent from a system they don't know.


But First, Some Advice to Save Your Reputation

In the next section, you'll learn about a new function called send_mail, which you can use to send mail with a Perl program. This tool is very useful and very dangerous at the same time. Sending email to someone is a small invasion of his or her privacy. You're asking the recipient of the mail to give you some of his or her time and disk space. You're also asking for every system between yours and the recipient's to relay this mail for you. This is a lot to ask from complete strangers.

The following are some tips on Netiquette for sending mail with Perl—or any other tool:

  • Test your code with well-known addresses—such as your own—and small messages first. Disasters happen all the time; avoid creating one.

  • Do not send unsolicited commercial email. Unsolicited commercial email—commonly known as spam—has become a major problem on the Internet. A small number of people like receiving this kind of mail. The rest of the recipients have reactions ranging from annoyance to outrage. A corporate entity sending the mail will find itself the target of many angry people. When you collect an email address, always ask whether it's okay to send mail back to that address at a later time. Always respect people's wishes to be removed from mailing lists.

  • Do not send out large volumes of mail, whether requested or not, at one time; pace yourself. First, your local mail relay host can get overwhelmed in a hurry, and your local ISP will terminate your account to control the damage. Second, if a target ISP begins to be overwhelmed by your mail, the provider may simply block all email from your domain. Losing the ability to send any mail at all to large domains—aol.com, hotmail.com, and so on—can ruin your day, will likely get your account with your ISP terminated, and may result in your being sued.

  • Provide good return email addresses, especially in the header. Make sure the From: (or Reply To:) address of your email is correct, especially when it was sent from a machine. It is possible to use Perl to forge email, but the forgery does contain a trail back to you. Forging mail can get you into serious trouble.

  • Always use your own mail relay host. Abusing other system's email relays will get your account terminated quickly, and may get you sued or worse.

  • Do not send huge email messages, or lots of smaller messages, to unsuspecting people; this is called mailbombing and will likely get your ISP account terminated, and may cause legal touble.

Not all these tips are simply good Netiquette. Breaking some of these rules can get you removed from your Internet service provider and/or sued for damages by your ISP and recipients. When you signed up for your ISP account, you were most likely told that any of the above reasons are grounds for termination and possibly make you liable for damages.

Be conservative in what you produce, liberal in what you accept.

Note

The Internet has a very long collective memory. People who have truly abused email are long remembered and loathed. Once a reputation is soiled by spamming, it's very hard to fix.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.124.53