=================================================== sample SMTP session using the "netcat" (nc) command =================================================== -Ian! D. Allen - idallen@idallen.ca - www.idallen.com The "nc" (netcat) TCP/IP "Swiss Army Knife" program is a "pure" way to connect your keyboard with a remote TCP/IP daemon. It is similar to "telnet", except it doesn't try to auto-negotiate any line parameters first. It is useful for connecting directly to many text-based Internet protocols. Use "nc" in preference to "telnet", when available. One such text-based protocol is the Simple Mail Transfer Protocol (SMTP) used to send EMail over the Internet. This protocol is only used for *sending* email, not for receiving email. It is documented in RFC2821: http://tools.ietf.org/html/rfc2821 http://www.faqs.org/rfcs/rfc2821.html To find which machine handles mail for a domain, look up the MX record in the DNS: $ host -t mx carleton.ca carleton.ca mail is handled by 10 smtp-external.ccs.carleton.ca. My input is marked by "*" in the examples below. This particular SMTP server has all the HELP commands enabled. A summary session follows this extended SMTP session below. Note that for strict adherence to the SMTP RFC, lines should end in CR+LF, which may require typing CTRL-V at the end of each line typed. * $ nc -v smtp-external.ccs.carleton.ca smtp DNS fwd/rev mismatch: smtp-external.ccs.carleton.ca != smtp-external.carleton.ca smtp-external.ccs.carleton.ca [134.117.1.18] 25 (smtp) open 220 ccs.carleton.ca ESMTP Sendmail 8.13.4/8.13.4; Sat, 17 Feb 2007 04:27:32 -0500 (EST) * help 214-2.0.0 This is sendmail version 8.13.4 214-2.0.0 Topics: 214-2.0.0 HELO EHLO MAIL RCPT DATA 214-2.0.0 RSET NOOP QUIT HELP VRFY 214-2.0.0 EXPN VERB ETRN DSN AUTH 214-2.0.0 STARTTLS 214-2.0.0 For more info use "HELP ". 214-2.0.0 To report bugs in the implementation send email to 214-2.0.0 sendmail-bugs@sendmail.org. 214-2.0.0 For local information send email to Postmaster at your site. 214 2.0.0 End of HELP info * help ehlo 214-2.0.0 EHLO 214-2.0.0 Introduce yourself, and request extended SMTP mode. 214-2.0.0 Possible replies include: 214-2.0.0 SEND Send as mail [RFC821] 214-2.0.0 SOML Send as mail or terminal [RFC821] 214-2.0.0 SAML Send as mail and terminal [RFC821] 214-2.0.0 EXPN Expand the mailing list [RFC821] 214-2.0.0 HELP Supply helpful information [RFC821] 214-2.0.0 TURN Turn the operation around [RFC821] 214-2.0.0 8BITMIME Use 8-bit data [RFC1652] 214-2.0.0 SIZE Message size declaration [RFC1870] 214-2.0.0 VERB Verbose [Allman] 214-2.0.0 CHUNKING Chunking [RFC1830] 214-2.0.0 BINARYMIME Binary MIME [RFC1830] 214-2.0.0 PIPELINING Command Pipelining [RFC1854] 214-2.0.0 DSN Delivery Status Notification [RFC1891] 214-2.0.0 ETRN Remote Message Queue Starting [RFC1985] 214-2.0.0 STARTTLS Secure SMTP [RFC2487] 214-2.0.0 AUTH Authentication [RFC2554] 214-2.0.0 ENHANCEDSTATUSCODES Enhanced status codes [RFC2034] 214-2.0.0 DELIVERBY Deliver By [RFC2852] 214 2.0.0 End of HELP info * ehlo idallen.ca 250-ccs.carleton.ca Hello idallen.ca [72.18.159.15], pleased to meet you 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-EXPN 250-VERB 250-8BITMIME 250-SIZE 26214400 250-ETRN 250-DELIVERBY 250 HELP * help mail 214-2.0.0 MAIL FROM: [ ] 214-2.0.0 Specifies the sender. Parameters are ESMTP extensions. 214-2.0.0 See "HELP DSN" for details. 214 2.0.0 End of HELP info * mail from: 250 2.1.0 ... Sender ok * help rcpt 214-2.0.0 RCPT TO: [ ] 214-2.0.0 Specifies the recipient. Can be used any number of times. 214-2.0.0 Parameters are ESMTP extensions. See "HELP DSN" for details. 214 2.0.0 End of HELP info * rcpt to: 250 2.1.5 ... Recipient ok * help data 214-2.0.0 DATA 214-2.0.0 Following text is collected as the message. 214-2.0.0 End with a single dot. 214 2.0.0 End of HELP info * data 354 Enter mail, end with "." on a line by itself * From: idallen@idallen.ca * To: idallen@connect.carleton.ca * Subject: this is a test message via SMTP * * hello Ian! * . 250 2.0.0 l1H9RWKB006182 Message accepted for delivery * help quit 214-2.0.0 QUIT 214-2.0.0 Exit sendmail (SMTP). 214 2.0.0 End of HELP info * quit 221 2.0.0 ccs.carleton.ca closing connection To summarize just the essential SMTP commands (no HELP, shortened reply codes): * $ nc smtp-external.ccs.carleton.ca smtp 220 ccs.carleton.ca ESMTP Sendmail 8.13.4/8.13.4; Sat, 17 Feb 2007 04:27:32 -0500 (EST) * ehlo idallen.ca 250 ccs.carleton.ca Hello idallen.ca [72.18.159.15], pleased to meet you * mail from: 250 2.1.0 ... Sender ok * rcpt to: 250 2.1.5 ... Recipient ok * data 354 Enter mail, end with "." on a line by itself * From: idallen@idallen.ca * To: idallen@connect.carleton.ca * Subject: this is a test message via SMTP * * hello Ian! * . 250 2.0.0 l1H9RWKB006182 Message accepted for delivery * quit 221 2.0.0 ccs.carleton.ca closing connection Note the difference between the SMTP RFC2821 "envelope" FROM/TO lines and the RFC2822 Message From:/To: lines. The Message From:/To: lines need not be related to the SMTP RFC2821 envelope FROM/TO lines, and application writers are warned not to try to link them: (RFC 2821 Section 7.2)