141

我有一个 SMTP 服务器,出于这个问题的目的,我们称之为:smtp.mydomain.com。

如何检查 SMTP 服务器是否在工作?我可以从 Linux 命令行手动发送电子邮件吗?

4

4 回答 4

191

使用 telnet 建立原始网络连接的语法如下:

telnet {domain_name} {port_number}

所以 telnet 到你的 smtp 服务器

telnet smtp.mydomain.com 25

并复制并粘贴以下内容

helo client.mydomain.com
mail from:<sender@mydomain.com>
rcpt to:<to_email@mydomain.com>
data
From: test@mydomain.com
Subject: test mail from command line

this is test number 1
sent from linux box
.
quit

注意:不要忘记“。” 最后代表消息的结束。“退出”行退出结束会话。

于 2012-08-16T13:40:31.097 回答
30

使用 telnet 测试 postfix 或其他 SMTP 的唯一事情是您必须了解命令和语法。相反,只需使用swaks :)

thufir@dur:~$ 
thufir@dur:~$ mail -f Maildir
"/home/thufir/Maildir": 4 messages
>    1 thufir@dur.bouncem                   15/553   test Mon, 30 Dec 2013 10:15:12 -0800
     2 thufir@dur.bouncem                   15/581   test Mon, 30 Dec 2013 10:15:55 -0800
     3 thufir@dur.bouncem                   15/581   test Mon, 30 Dec 2013 10:29:57 -0800
     4 thufir@dur.bouncem                   15/581   test Mon, 30 Dec 2013 11:54:16 -0800
? q
Held 4 messages in /home/thufir/Maildir
thufir@dur:~$ 
thufir@dur:~$ swaks --to thufir@dur.bounceme.net
=== Trying dur.bounceme.net:25...
=== Connected to dur.bounceme.net.
<-  220 dur.bounceme.net ESMTP Postfix (Ubuntu)
 -> EHLO dur.bounceme.net
<-  250-dur.bounceme.net
<-  250-PIPELINING
<-  250-SIZE 10240000
<-  250-VRFY
<-  250-ETRN
<-  250-STARTTLS
<-  250-ENHANCEDSTATUSCODES
<-  250-8BITMIME
<-  250 DSN
 -> MAIL FROM:<thufir@dur.bounceme.net>
<-  250 2.1.0 Ok
 -> RCPT TO:<thufir@dur.bounceme.net>
<-  250 2.1.5 Ok
 -> DATA
<-  354 End data with <CR><LF>.<CR><LF>
 -> Date: Mon, 30 Dec 2013 14:33:17 -0800
 -> To: thufir@dur.bounceme.net
 -> From: thufir@dur.bounceme.net
 -> Subject: test Mon, 30 Dec 2013 14:33:17 -0800
 -> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
 -> 
 -> This is a test mailing
 -> 
 -> .
<-  250 2.0.0 Ok: queued as 52D162C3EFF
 -> QUIT
<-  221 2.0.0 Bye
=== Connection closed with remote host.
thufir@dur:~$ 
thufir@dur:~$ mail -f Maildir
"/home/thufir/Maildir": 5 messages 1 new
     1 thufir@dur.bouncem                   15/553   test Mon, 30 Dec 2013 10:15:12 -0800
     2 thufir@dur.bouncem                   15/581   test Mon, 30 Dec 2013 10:15:55 -0800
     3 thufir@dur.bouncem                   15/581   test Mon, 30 Dec 2013 10:29:57 -0800
     4 thufir@dur.bouncem                   15/581   test Mon, 30 Dec 2013 11:54:16 -0800
>N   5 thufir@dur.bouncem                   15/581   test Mon, 30 Dec 2013 14:33:17 -0800
? 5
Return-Path: <thufir@dur.bounceme.net>
X-Original-To: thufir@dur.bounceme.net
Delivered-To: thufir@dur.bounceme.net
Received: from dur.bounceme.net (localhost [127.0.0.1])
    by dur.bounceme.net (Postfix) with ESMTP id 52D162C3EFF
    for <thufir@dur.bounceme.net>; Mon, 30 Dec 2013 14:33:17 -0800 (PST)
Date: Mon, 30 Dec 2013 14:33:17 -0800
To: thufir@dur.bounceme.net
From: thufir@dur.bounceme.net
Subject: test Mon, 30 Dec 2013 14:33:17 -0800
X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
Message-Id: <20131230223317.52D162C3EFF@dur.bounceme.net>

This is a test mailing

New mail has arrived.
? q
Held 5 messages in /home/thufir/Maildir
thufir@dur:~$ 

这只是一个简单的命令。

于 2013-12-30T22:46:13.013 回答
18
[root@piwik-dev tmp]# mail -v root@localhost
Subject: Test
Hello world
Cc:  <Ctrl+D>

root@localhost... Connecting to [127.0.0.1] via relay...
220 piwik-dev.example.com ESMTP Sendmail 8.13.8/8.13.8; Thu, 23 Aug 2012 10:49:40 -0400
>>> EHLO piwik-dev.example.com
250-piwik-dev.example.com Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
>>> MAIL From:<root@piwik-dev.example.com> SIZE=46
250 2.1.0 <root@piwik-dev.example.com>... Sender ok
>>> RCPT To:<root@piwik-dev.example.com>
>>> DATA
250 2.1.5 <root@piwik-dev.example.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 q7NEneju002633 Message accepted for delivery
root@localhost... Sent (q7NEneju002633 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 piwik-dev.example.com closing connection
于 2012-08-23T14:52:44.147 回答
2

不确定这是否有帮助,但这是一个命令行工具,可让您简单地从 SMTP 服务器发送测试邮件。http://code.google.com/p/woodpecker-tester/

于 2012-10-26T09:21:56.330 回答