Tuesday, August 4, 2009

Send Email via Telnet

WARNING: Contains ferociously nerdical content
On occasion, we write code that sends email. Sometimes, it actually works the first time.
More often, we need to figure out why not.
While it's nicest to have the computer emulate what the human would get bored doing, sometimes it helps to have the human do what the computer can't quite seem to do on its own.
For that reason, we sometimes resort to manual telnet sessions with a remote mail server.
Simple manual telnet session with mail host
Uppercase/lowercase does not appear to be significant.
You do/type this
Server responds with
Telnet to hostname on port 25
220 (then identifies itself - possibly with several lines of 220 + text)
HELO your_domain_name or whatever
250 (followed by human readable message)
MAIL FROM:you@hostname.com (ie, your email address)
250 is syntactically correct (or similar)
RCPT TO:them@someplace_else.com (email address you want to send to)
250 is syntactically correct
DATA
Tells you to send data then CRLF period CRLF at end
You type your message then CRLF period CRLF (ie, type a period on a line by itself then hit ENTER)
250
QUIT
Signoff message

How to check whether SMTP port 25 is blocked?

How to check whether SMTP port 25 is blocked?
The standard port used for SMTP connections is 25. One of the most common reasons for not being able to send messages is that your Internet service provider blocks this port. This is why using an alternative SMTP port is highly recommended.
Here's how to, depending on your OS, check whether your ISP blocks port 25:
· Check port 25 in Windows

Click on the Start menu button, usually located at the lower left corner of the screen. There is a tab called "Run". Click it and a new window will pop up. In the text field of this window you need to type
cmd and then press the "Enter" key. Another window will open. It is the so called "MS-DOS prompt" or "command prompt". Just type the following command in the command prompt window and press "Enter":
telnet my-domain-name.com 25
· Check port 25 in Mac OS

Each Mac OS is delivered with a preinstalled terminal emulator. The terminal is a tool which allows you to execute commands from the command line. Usually, the terminal is located under your Mac HD -> "Applications" directory -> Utilities sub-directory. When the window opens, you will see a command line with a flashing cursor on it so you can start typing right away. Just type the following command and press "Enter":
telnet my-domain-name.com 25
· Check port 25 in Linux
Open your favorite terminal emulator and execute the following command in order to check the connection on port 25 to your website:
telnet my-domain-name.com 25
Results from the 25 port check

If the test is successful, you should receive a message similar to this one:
220-serv01.siteground173.com ESMTP Exim 4.63 #1 Wed, 18 Apr 2008 07:17:30 -0500
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.

If you get a message saying that the connection is refused we recommend that you use the alternative port for your SMTP connection.
What is the alternative SMTP port and how to configure an email client to use it?
The reason why most ISPs block the default SMTP port 25 is because it is used for sending unsolicited emails.
Fortunately, web hosting providers such as SiteGround offer an alternative SMTP port for the convenience of their customers.
The alternative SMTP port all SiteGround customers can use is 2525.
Information on how to change the SMTP port for the most popular mail clients can be found in our Email tutorial.
If you wish to be able to use an alternative SMTP port, as well as have unlimited mail accounts and stable mail service, you may sign up for an account at SiteGround. Our servers are using state of the art spam protection system with custom ACL filters which will ensure you will avoid the spam and at the same time never miss your important emails.