Home About BC DR HA Support Training Download
You are here: Home/ Downloads/ Please Login or Register

-
Current Location
-

js
  Downloads



-
 Mt Xia Inc.
-
BOOK:Advanced Shell Scripting



 Join our LinkedIn Group
AIX Advanced Technical Experts
Contract Opportunities

www.LinkedIn.com
-
 Train By Tweet
Training courses Tweet By Tweet
Various Subjects and Products
TrainByTweet.com


AIX Admin Methodology
Global Consolidation Project
All AIX admins should join
www.aixexpert.com
-

digg Digg this page
del.icio.us Post to del.icio.us
Slashdot Slashdot it!


AIX FREE DEMO UNIX
Automated AIX Deployment
Reduce your DC costs

www.siteox.com

LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com

SMTP 101


The Simple Mail Transfer Protocol (SMTP) is the most widely used protocol to send messages by Message Transfer Agents (MTA) on the internet. MTAs are client or server programs that perform email services, such as sending or receiving mail for a host computer. The protocol is defined in RFC 821 and RFC 1123, and was designed to transfer mail independently of any specific transmission subsystem. SMTP demands an ordered data stream of 7-bit US-ASCII characters, and has size limitations on certain objects discussed below.

The SMTP model is based on what is called a mail transaction. Sender and receiver MTAs send commands and replies in a structured, lock-step process. The sender MTA initiates the transaction steps by sending SMTP commands to the receiver. The receiver MTA replies to the sender with numeric reply codes, followed by a text string with additional information about the reply code.

The Mail Transaction

The sender MTA initiates a two-way TCP communication channel between it and the receiver MTA, generally on port 25. Once the connection is open, the receiver MTA sends reply code 220 indicating that it is ready. The sender MTA then sends the HELO command with the client host as an argument. The HELO command identifies the sender MTA to the receiver MTA, and the receiver MTA will respond with a reply code 250. This tells the sender MTA that the connection is open and ready to go. This step in the transaction identifies and confirms host addresses for both the sender and receiver MTAs.

Example:

Sender:     (Open the TCP connection to port 25.) 
Receiver:   220 starfleet.org Simple Mail Transfer Service Ready 
Sender:     HELO walton.net 
Receiver:   250 starfleet.org 

The mail transaction is initiated by the MAIL command from the sender MTA. This command causes the receiver MTA to reset its state tables and buffers, including the recipients and mail data. The syntax for the MAIL command is

MAIL <space> FROM:<reverse-path> <CRLF>

Example:

Sender:    MAIL FROM:<johnboy@walton.net> 
Receiver:   250 OK 

The reverse-path is the full reverse source route list, starting with the current client host and ending with the user mailbox. The reverse-path is modified by each MTA as the message travels toward its destination. Before transferring a message to the next relay host, the current host will remove its name from the beginning of the forward-path and adds its name to the beginning of the reverse path.

The forward-path is used in the next command, RCPT.

RCPT <space> TO:<forward-path> <CRLF> 

Example:

Sender:    RCPT TO:<riker@starfleet.org> 
Receiver:   250 OK 

If the mailbox address is acceptable to the receiver MTA, it transmits a reply code 250 to the sender MTA. If it cannot fulfill the request, it transmits a reply code of 550. One reason it may not be able to fulfill the request is because the mailbox is incorrect or non-existent.

The next step is for the sender MTA to issue the DATA command. There are no arguments to this command, it simply tells the receiver that the sender is ready to start sending the message. The receiver MTA will transmit a reply code 354 indicating that it is ready to receive the message. Once the sender MTA receives the correct reply code, it sends the mail data to the receiver. The mail data is followed by a <CRLF>.<CRLF> sequence indicating that there is no more data.

DATA <CRLF> 

Example:

Sender:    DATA 
Receiver:   354 Start mail input; end with <CRLF>.<CRLF> 
Sender:    yada yada yada... 
Sender:    blah blah blah... 
Sender:    . 
Receiver:   250 OK 

When the receiver MTA responds with the reply code 250, acknowledging receipt of the message, the sender MTA transmits the QUIT command. The receiver MTA sends the reply code 221, and the mail transaction is complete.

Sender:    QUIT 
Receiver:   221 starfleet.org Service closing transmission
channel 

SMTP Commands

The following are the SMTP commands. The commands marked "Required" are the ones specified by RFC 821 and RFC 1123 which must be part of a minimal SMTP implementation.

Command Required Description
HELO * Identifies server
MAIL * Initiates the mail transaction
RCPT * Identifies mail recipient
DATA * Initiates mail data transfer
RSET * Aborts the current mail transaction
NOOP * Receiver returns OK. Used to test the server connection
QUIT * Close the connection
VRFY * Verify recipient exists
SEND   Delivers message to one or more terminals
SOML   Delivers message to one or more terminals or mailboxes
SAML   Delivers message to one or more terminals and mailboxes
EXPN   Expand mailing list addresses
HELP   Requests Help info from receiver
TURN   Asks receiver to take role as server

SMTP Reply Codes

The following are the SMTP reply codes sent from the receiver MTA.

SMTP Reply Codes Description
211 System Status or system help reply
214 Help message
220 Service ready
221 Service closing transmission channel
250 Requested action OK and completed
251 User not local; will forward to
354 Start mail input; end with .
421 Service not available, closing connection
450 Mailbox unavailable, requested mail action not taken
451 Local error in processing, action aborted
452 Insufficient system storage, action not taken
500 Syntax error, command unrecognized
501 Syntax error in parameters or arguments
502 Command not implemented
503 Bad sequence of commands
504 Command parameter not implemented
550 Mailbox unavailable, action not taken
551 User not local; please try
552 Exceeded storage allocation, action aborted
553 Mailbox name not allowed, action not taken


The following is a shell script used to send text and binary attachments via sendmail.


#!/usr/bin/ksh93
################################################################

MAILADDR="username@domain.com"
REPLYTO="username@domain.com"
SUBJECT="test binary file attachment"

exec 3>&-
exec 3>/dev/tcp/mailhost.domain.com/25

print -u3 "HELO ${REPLYTO#*@}"
print -u3 "MAIL FROM: ${REPLYTO}"
print -u3 "RCPT TO: ${MAILADDR}"

print -u3 "DATA
Subject: ${SUBJECT}
To: ${MAILADDR}
From: ${REPLYTO}
Reply-to: ${REPLYTO}
Mime-Version: 1.0
Content-Type: Multipart/Mixed; boundary=foo

--foo
Content-Type: text/plain;charset=\"ISO-8859-1\"

"

print "Sending TextFile.txt"
cat TextFile.txt >&3

print -u3 '\n\n--foo
Content-Type: text/plain;charset="ISO-8859-1"
Content-Disposition: attachment;filename="TextFile.txt"
    
'

print "Sending ${BinaryFile}"
cat ${BinaryFile} >&3

print -u3 '\n\n--foo
Content-Type: application/x-msword;name="MSWordFile.doc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;filename="MSWordFile.doc"
    
'

print "Sending ../MSWordFile.doc"
perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)' < ../MSWordFile.doc >&3

print -u3 "\n\n."

print -u3 "QUIT"

exec 3>&-

-
SMTP 101
-
 


AIX FREE DEMO UNIX
Automated AIX Deployment
Reduce your DC costs

www.siteox.com

LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com