﻿{"id":1322,"date":"2015-06-10T13:23:00","date_gmt":"2015-06-10T05:23:00","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=1322"},"modified":"2019-04-29T14:03:47","modified_gmt":"2019-04-29T06:03:47","slug":"send-a-test-mail-using-telnet","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/linux\/1322","title":{"rendered":"Send a test mail using Telnet"},"content":{"rendered":"<div id=\"emulating-an-smtp-session-with-telnet\" class=\"section\">\n<h2>Emulating an SMTP session with Telnet<\/h2>\nLet us try to send an email to the user now. As the &#8220;example.com&#8221; domain does not really existing your DNS settings will likely not point to the right server. So we are simulating an SMTP session with the <em>telnet<\/em> command. Install the telnet package if you haven&#8217;t already:\n<pre class=\"rteindent1\">$> <strong>aptitude install telnet<\/strong><\/pre>\nThen establish a TCP\u00a0connection to the SMTP\u00a0port:\n<pre class=\"literal-block rteindent1\">$> <strong>telnet localhost smtp<\/strong>\n<\/pre>\nThe server should reply:\n<pre class=\"literal-block rteindent1\">Trying 127.0.0.1...\nConnected to localhost.\nEscape character is '^]'.\n220 mailtest ESMTP Postfix (Debian\/GNU)\n<\/pre>\nGreat. Postfix is listening and wants us to speak SMTP. First we need to be friendly:\n<pre class=\"literal-block rteindent1\"><strong>ehlo example.com<\/strong>\n<\/pre>\nPostfix appreciates our friendliness and tells us which features it provides:\n<pre class=\"literal-block rteindent1\">250-my-new-mailserver\n250-PIPELINING\n250-SIZE 10240000\n250-VRFY\n250-ETRN\n250-ENHANCEDSTATUSCODES\n250-8BITMIME\n250 DSN\n<\/pre>\nHey, Postfix, we have a mail from <a class=\"reference external\" href=\"mailto:steve@example.com\">steve@example.com<\/a>:\n<pre class=\"literal-block rteindent1\"><strong>mail from:<steve@example.com><\/strong>\n<\/pre>\nLooks like Postfix is happy with that because return codes that start with a &#8216;2&#8217; are good news:\n<pre class=\"literal-block rteindent1\">250 2.1.0 Ok\n<\/pre>\nTell Postfix who the recipient of the mail is:\n<pre class=\"literal-block rteindent1\"><strong>rcpt to:<john@example.com><\/strong>\n<\/pre>\nPostfix accepts that:\n<pre class=\"literal-block rteindent1\">250 2.1.5 Ok\n<\/pre>\nThen we are ready to send the actual mail:\n<pre class=\"literal-block rteindent1\"><strong>data<\/strong>\n<\/pre>\nPostfix agrees and tells us we can send the actual mail now and end our input with a dot on an empty line:\n<pre class=\"literal-block rteindent1\">354 End data with <CR><LF>.<CR><LF>\n<\/pre>\nOkay, type in the mail:\n\nsubject:\u4e3b\u9898\n\nfrom:<xxx@163.com> \u00a0 \u4e0e\u4e0a\u9762 \u00a0mail from \u00a0\u8f93\u5165\u7684\u4e00\u6837 \u00a0 \u81ea\u5df1\u7684\u90ae\u7bb1\n\nto:<xxx@qq.com> \u00a0 \u00a0\u4e0e\u4e0a\u9762\u7684rctp to \u4e00\u6837\n\n<strong>\nHi John, just wanted to drop you a note. .<\/strong>\n\nPostfix tells us it has received the mail and queued under a queue ID:\n<pre class=\"literal-block rteindent1\">250 2.0.0 Ok: queued as A9D64379C4\n<\/pre>\nThanks, Postfix, we are done:\n<pre class=\"literal-block rteindent1\"><strong>quit<\/strong>\n<\/pre>\n<\/div>\n<div id=\"checking-the-logs\" class=\"section\">\n<h2>Checking the logs<\/h2>\nTake a look at the <tt class=\"docutils literal\"><span class=\"pre\">\/var\/log\/mail.log<\/span><\/tt> file now. You should see something similar to:\n<pre class=\"literal-block rteindent1\">postfix\/smtpd[...]: connect from localhost[127.0.0.1]\npostfix\/smtpd[...]: 5FF712A6: client=localhost[127.0.0.1]\npostfix\/cleanup[...]: 5FF712A6: message-id=<...>\npostfix\/qmgr[...]: 5FF712A6: from=<steve@example.com>, size=364, nrcpt=1 (queue active)\npostfix\/pipe[...]: 5FF712A6: to=<john@example.com>, relay=dovecot, ..., status=sent (delivered via dovecot service)\npostfix\/qmgr[...]: 5FF712A6: removed\npostfix\/smtpd[...]: disconnect from localhost[127.0.0.1]\n<\/pre>\nThe delivery has worked. Postfix has correctly determined that the destination domain is a virtual domain and forwarded the email to the &#8216;dovecot&#8217; service.\n\n<\/div>\n<div id=\"checking-the-user-s-maildir\" class=\"section\">\n<h2>Checking the user&#8217;s mailbox<\/h2>\nThe email should now be somewhere under <tt class=\"docutils literal\"><span class=\"pre\">\/var\/vmail\/example.com\/john<\/span><\/tt>. Let us take a look:\n<pre class=\"literal-block rteindent1\">$> <strong>cd \/var\/vmail\/example.com\/john\/Maildir<\/strong>\n$> <strong>find<\/strong>\n.\n.\/cur\n.\/new\n.\/new\/1179521979.V801I2bbf7M15352.mailtest\n.\/tmp\n<\/pre>\nThere sits the email. Try to read the mail with the &#8220;mutt&#8221; program:\n<pre class=\"literal-block rteindent1\">$> <strong>mutt -f .<\/strong>\n<\/pre>\nThe new email is shown:\n<pre class=\"literal-block rteindent1\">q:Quit  d:Del  u:Undel  s:Save  m:Mail  r:Reply  g:Group  ?:Help\n   1 N   May 18 steve@example.c (0.1K)\n<\/pre>\nPress ENTER to read the email:\n<pre class=\"literal-block rteindent1\">From: steve@example.com\nTo: undisclosed-recipients: ;\n\nHi John,\n\njust wanted to drop you a note.\n<\/pre>\nSo the email arrived at John&#8217;s account. Perfect. Choose &#8216;q&#8217; twice to exit mutt again.\n\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Emulating an SMTP session with Telnet Let us try to send an email to the user now. As the &#8220;exa&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[415,414,413,416],"class_list":["post-1322","post","type-post","status-publish","format-standard","hentry","category-linux","tag-mail","tag-smtp","tag-telnet","tag-test"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=1322"}],"version-history":[{"count":3,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1322\/revisions"}],"predecessor-version":[{"id":1849,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1322\/revisions\/1849"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=1322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=1322"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=1322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}