The Exchange 2007 Wiki

Speak SMTP Like a Native

If you are writing an SMTP agent, you might find it instructive to learn to speak SMTP yourself, both to aid debugging and to get a feel for what is happening “under the hood” when Exchange receives a message from the internet. This is a lot easier than it might sound. Open the Run dialog box (press Windows Key + R) and enter “telnet localhost smtp” (or substitute the name of your Edge Transport server in place of localhost). This will open a window where you can talk with the server. The server will begin the conversation by sending a banner, such as:

220 mail.contoso.com ready at Thu, 23 Feb 2006 17:46:23 -0800

You may continue the conversation by entering the following commands, one line at a time.

Note: There is a blank line in the middle – it’s important. Just press enter to send the blank line:

 

ehlo console
mail from:
sender@contoso.com
rcpt to: recipient@contoso.com
data
To:
recipient@contoso.com
From: sender@contoso.com
Subject: Test Message

This a test message.
.
quit

 

The server will respond with a simple text message after the first three commands. After the “data” command, the server will just listen patiently until you enter the “.” on a line by itself. When you initially connect to the server, your agent will be created and the OnConnect event will be fired. Additional events are fired are follows:

  • ehlo console        This fires OnEhloCommand
  • mail from: sender@contoso.com        This fires OnMailCommand
  • rcpt to: recipient@contoso.com        This fires an OnRcptCommand. You can repeat this command as many times as you want, specifying a different email address each time.
  • Data        This fires OnDataCommand. The next three lines are not SMTP commands, they are the headers of the message that you are sending.
  • To: recipient@contoso.com From: sender@contoso.com Subject: Test Messageblank line)        The blank line is important, it seperates the headers from the content of the message. When the blank line is received, OnEndOfHeaders fires.
  • This is a test message..        The "." on a line by itself indicates the end of the message, and this is when OnEndOfData fires.
  • Quit        This is the polite way to end the conversation. OnDisconnect will fire at this point, but it will also fire if you end the connection impolitely (for example by closing the window).

You can also copy/paste the whole batch of commands, put them in a text file so you can replay an entire SMTP conversation quickly using only notepad and telnet. This can be really handy for testing.

Site

Changes
Index
Search

 

User

 

Log In
Register

 
 

Last Modified 8/4/06 9:36 AM