My 2 paisas

Sending emails using telnet

Posted on: June 25, 2009

  • Coutsey to Bob Peers>
  • Sending emails using telnet.

    The basics.

    Before starting it’s important to know a few things:

    SMTP address.

    The SMTP server address of a provider you are permitted to use. Usually this will be you ISP’s SMTP server but could be any other, if you are not sure of the address
    then look at the settings in your email client. Otherwise the site has a long
    list of SMTP servers.

    Port blocking.

    To prevent spamming it’s possible that your ISP blocks the default SMTP port, port 25. If this is the case and you try to connect to a different SMTP server (other
    than your ISP’s smtp server) then you will probably just get a timeout when you try to connect. Some email providers allow you to use an alternate port, in my
    case I use and they allow you to use port 26, but you will have to check with your
    account provider first.


    If you are able to connect to another SMTP that’s not your ISP’s then you will (or should) only be able to send an email to a user of that email provider. For example I can
    connect using telnet to my email provider at and send an email to another Fastmail user since they have to accept mail to their users (otherwise they would
    not be able to receive any mail), but if I try to send an email to another email address, say then I will be denied since then I’m using’s
    SMTP server as a mail relay which is not allowed without authentication.

    Using telnet.

    If you make a mistake you cannot use backspace to delete the entry, you may have to press enter to get an error and then re-type the command or quit and start again.

    Connecting to the host.

    With this in mind it’s very easy to send a basic text email just using telnet which is installed on most computers. First open up a terminal and type the following, of
    course replacing with the address of your SMTP server:

    telnet 25

    This should return something like:

    telnet 25
    Connected to (
    Escape character is '^]'.
    220 ESMTP Postfix (Debian/GNU)

    HELO command.

    Next we need to introduce ourselves using the helo command, in reality this can be anything and the mail will still be sent OK (although a false helo command
    will result in a spam score from spamassasin for example).

    helo mail.localhost

    MAIL FROM command.

    Next we type mail from: followed by your email address, if you use a name as well then you need to put angle brackets around you address,
    like Bob Peers <>, but the name is not necessary

    250 Ok

    RCPT TO command.

    Now type rcpt to: followed by who you are sending the mail to, following the same rules as above. Note that this IS NOT the address that appears on the To: line in
    your email client or webmail, the two are completely unrelated which is why you can receive spam when your email address is not listed on the To: line.

    250 Ok

    DATA command.

    Now for the actual mail body, type the word ‘data’ and press enter:

    354 End data with <CR><LF>.<CR><LF>

    Your SMTP server might not display the extra help here but it simply means that we type our mail body now and to end the input press enter then type a single .
    followed by pressing enter again. At this point we can add extra headers if we wish but they are not required. This just shows that the To and From fields are just
    part of the message body and have nothing to do with the delivery of the email. However if you do not add them then the message will arrive with
    ‘To: undisclosed-recipients:; in the To field, which again will probably cause your message to be assigned a spam score. If you do decide to add these extra
    headers make sure you leave a blank line between them and the ‘real’ text you wish to appear in the body of the message.

    to:Joe Bloggs<>
    from: Bob Peers<>
    subject:Telnet test

    Hope you are following along OK...
    250 Ok: queued as 4DDFB180CDA

    To actually send the mail we need to quit the telnet session by typing ‘quit’.

    221 Bye
    Connection closed by foreign host.


    If all goes well you should get the email without problems, that’s basically all there is to it. Many of the extra lines are not really required, as long as you type
    the ‘helo’, ‘mail from:’ and ‘rcpt to:’ commands along with ‘data’, terminating ‘.’ and ‘quit’ the mail should be sent.

    Relay access denied error.

    If you try to send an email to an external address when you are not permitted you will get some output like below (this is using my Fastmail account).

    telnet 25
    Connected to (
    Escape character is '^]'.
    220 ESMTP . No UCE permitted.
    helo mail.localhost
    250 Ok
    554 <>: Relay access denied
    221 Bye
    Connection closed by foreign host.
    Tags: ,

    Leave a Reply

    Fill in your details below or click an icon to log in: Logo

    You are commenting using your account. Log Out /  Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )


    Connecting to %s

    Links that I liked to save

    Blog Stats

    • 45,141 hits
    %d bloggers like this: