user-avatar
Today is Friday
November 22, 2024

June 25, 2009

Sending emails using telnet

by viggy — Categories: Uncategorized — Tags: , Leave a comment
  • 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 E-Eeasy.com 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 Fastmail.fm and they allow you to use port 26, but you will have to check with your
    account provider first.

    Relaying.

    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 Fastmail.fm 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 someone@hotmail.com then I will be denied since then I’m using Fastmail.fm’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 mail.yourserver.dk with the address of your SMTP server:

    telnet mail.yoursever.dk 25

    This should return something like:

    telnet mail.yoursever.dk 25
    Trying 172.16.0.2...
    Connected to mail.yoursever.dk (172.16.0.2).
    Escape character is '^]'.
    220 cirkeline.yoursever.dk 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
    250 mail.yoursever.dk

    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 <email@domain.dk>, but the name is not necessary

    mail from:me@domain.dk
    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.

    rcpt to:you@domain.com
    250 Ok

    DATA command.

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

    data
    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<you@domain.com>
    from: Bob Peers<me@domain.dk>
    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’.

    quit
    221 Bye
    Connection closed by foreign host.

    Summary

    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 mail.messagingengine.com 25
    Trying 66.111.4.160...
    Connected to mail.messagingengine.com (66.111.4.160).
    Escape character is '^]'.
    220 frontend2.messagingengine.com ESMTP . No UCE permitted.
    helo mail.localhost
    250 frontend2.messagingengine.com
    mail from:someone@somewhere.dk
    250 Ok
    rcpt to:someoneelse@hotmail.com
    554 <someoneelse@hotmail.com>: Relay access denied
    quit
    221 Bye
    Connection closed by foreign host.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>