Part 10. Working with a mail server using telnet
- Details
- Category: Mail Server
- Published: Thursday, 11 July 2019 12:14
- Written by Super User
- Hits: 2420
After we have configure the mail server, it is necessary to check its work. Of course this can be done using a mail client, but sometimes easier and faster to do it with the utility telnet.
The mail server for sending the message uses the SMTP protocol, which by default works on tcp-port 25. It is quite possible to find it on port 587. Port 587 uses a validation-submission-SMTP service, but this does not mean that the mail server client's authorization on the port will not pass on port 25.
If we set up authentication, then the login and password must be encoded, so you first need to create these encoded strings.
$ perl -MMIME::Base64 -e 'print encode_base64("user\@study.local");'
bXlfbG9naW4K
$ perl -MMIME::Base64 -e 'print encode_base64("PASSWORD");'
bXlfcGFzc3dvcmQK
We will enter these values instead of the login and password in our SMTP session.
Open our session on the command line
$ telnet mail-server 25
or, in the case of the STARTTLS session and port 587
$ openssl s_client -starttls smtp -crlf -connect mail-server:587
The following is a sequence of commands for sending a letter and comments to them.
Trying 192.168.0.114...Connected to mail-srv.Escape character is '^]'. | The console displays an attempt to connect to the server |
220 mail.study.local ESMTP (ubuntu) | If the connection is successful, than server displays a welcome line |
ehlo test.com | Enter the line of greetings |
250- mail-srv250-PIPELINING250-SIZE 10240000250-VRFY250-ETRN250-AUTH PLAIN LOGIN250-AUTH=PLAIN LOGIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN | And we get the answer from the server |
auth login | If authorization on the server is required, enter this line. If authorization is not required, skip this command and continue typing from the command "mail from:" |
334 VXNlcm5hbWU6 | And we get the answer from the server |
bXlfbG9naW4K | Enter our login in base64 format, which we received at the beginning |
334 UGFzc3dvcmQ6 | Get the answer from the server |
bXlfcGFzc3dvcmQK | Enter our password in base64 format, which we received at the beginning |
235 2.7.0 Authentication successful | Successful authentication report |
mail from: This email address is being protected from spambots. You need JavaScript enabled to view it. | Specify the sender's mail address |
250 2.1.0 Ok | The response from the server that the address is accepted |
rcpt to: This email address is being protected from spambots. You need JavaScript enabled to view it. | Specify the recipient's mail address |
250 2.1.5 Ok | The response from the server that the address is accepted |
data | After entering this command starts the mail itself |
354 End data with <CR><LF>.<CR><LF> | Get the answer from the server |
subject: test telnet auth | If you need a Subject - enter the command |
test. | Here we wrote the letter. We MUST HAVE to end with the sequenceENTER . ENTER |
250 2.0.0 Ok: queued as 415211810C6 | The response from the server that the mail is accepted and delivered to the queue |
quit | Enter the command of the end of work |
221 2.0.0 ByeConnection closed by foreign host. | The server announces the end of the session |
After that, the letter will be accepted by the server and sent to the address of the recipient.
Now test IMAP-server.
We use this same utility telnet.
Let’s connect to the server
$ telnet mail-server 143
If the connection to the IMAP server is encrypted (by SSL), then the connection command is as follows:
$ openssl s_client -crlf -ign_eof -connect mail-server:993
The following is a sequence of commands for working with the IMAP-server and comments to them.
Trying 192.168.0.114...Connected to mail-srv.Escape character is '^]'. | The console displays an attempt to connect to the server |
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE AUTH=PLAIN AUTH=LOGIN] Dovecot ready | If the connection is successful, than server displays a welcome line |
. login our-login our-password | After the .login command, enter the same login and password in the cleartext format |
. OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS] Logged in | Successful login report |
. list "" "*" | Enter the command for the viewing list of email folders |
* LIST (\HasNoChildren) "." "Drafts"* LIST (\HasNoChildren) "." "Spam"* LIST (\HasNoChildren) "." "Trash"* LIST (\HasNoChildren) "." "Sent"* LIST (\HasNoChildren) "." "INBOX". OK List completed. | The server displays a list of folders |
. status INBOX (messages) | We ask the server for the status of the Inbox |
* STATUS "INBOX" (MESSAGES 1086). OK Status completed. | The server displays the folder status |
. select inbox | Select the inbox for further work |
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent Junk NonJunk $Forwarded KMAILFORWARDED KMAILTODO KMAILWATCHED KMAILIGNORED $TODO $WATCHED $IGNORED receipt-handled $label2 $has_cal)* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent Junk NonJunk $Forwarded KMAILFORWARDED KMAILTODO KMAILWATCHED KMAILIGNORED $TODO $WATCHED $IGNORED receipt-handled $label2 $has_cal \*)] Flags permitted.* 1086 EXISTS* 0 RECENT* OK [UNSEEN 1085] First unseen.* OK [UIDVALIDITY 1242120321] UIDs valid* OK [UIDNEXT 138212] Predicted next UID* OK [HIGHESTMODSEQ 187388] Highest. OK [READ-WRITE] Select completed. | Server response |
. fetch 7 full | We give the command to the server to show the letter #7 |
* 7 FETCH (FLAGS (\Seen) INTERNALDATE "12-Jul-2008 18:24:12 +0300" RFC822.SIZE 1935 ENVELOPE ("Sat, 12 Jul 2008 18:07:52 +0300 (EEST)" "test mail" (("test.com" NIL "isbear" "ukrpost.net")) (("test.com" NIL "isbear" "ukrpost.net")) (("test.com" NIL "isbear" "ukrpost.net")) ((NIL NIL "yakim" "test.com.net")) NIL NIL NIL "< This email address is being protected from spambots. You need JavaScript enabled to view it.>") BODY ("text" "plain" ("charset" "KOI8-U") NIL NIL "7bit" 279 8)). OK Fetch completed. | The server displays the headers of the letter |
. fetch 7 rfc822.text | Give the command server display the message #7 body |
Re: test mailthis is test mail | The server displays the message body |
. logout | Enter the command to end the work |
* BYE Logging out. OK Logout completed.Connection closed by foreign host | The server announces the end of the session |
You can buy the book "Mail server based on Postfix, Dovecot and RoundCube" in electronic form in the store