2012-08-16 37 views
95

我有一个SMTP服务器,为了这个问题的目的让我们叫它:smtp.mydomain.com。如何检查smtp是否从命令行工作(Linux)

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

+0

@Flexo这些问题不应该迁移而不是关闭吗?这看起来像属于Serverfault – Balmipour 2015-10-15 19:10:25

+1

@Balmipour旧问题无法迁移,即使是版主。在http://meta.stackexchange.com上讨论这个问题有很好的理由(我现在没有链接),但请注意,问题不会被删除。 – Flexo 2015-10-15 19:25:24

+0

在Meta上检查了几篇文章后,似乎(对我)迁移“刚”需要先重新打开。也许这对老问题是不可能的,顺便说一句。我想你比我更了解这一点。无论如何,谢谢你的回答。 我在meta帖子中读到的一个更相关的观点是迁移似乎需要一个“特别有价值”的问题。并不是说这个是无用的,但它也不是一颗宝石。 我不明白这一点,因为SO被其他网站如ServerFault/Linux或超级用户所高估,但我会继续辩论另一天(它也属于Meta,不是这样:) – Balmipour 2015-10-16 14:20:15

回答

125

远程登录到您的SMTP服务器一样

telnet smtp.mydomain.com 25 

语法:

telnet {smtp_domain_name} {port_number} 

复制并粘贴以下

helo your_domain.com 
mail from:<[email protected]_domain.com> 
rcpt to:<[email protected]_domain.com> 
data 
From: [email protected]_domain.com 
Subject: test mail from command line 

this is test number 1 
sent from linux box 
. 

注: “”不要忘了在代表消息结束的末尾

我在网络上发现了这个,并将其添加到堆栈溢出,因为许多事情最终都在这里。

+5

您应该等待服务器对每条命令的响应,以及如果得到并发生错误(4xx或5xx结果代码)则中止。 – tripleee 2012-08-16 14:01:27

+1

你需要在标题和消息之间有一个空白行,除了它是一个工作示例。 – martineg 2012-08-16 14:03:09

+1

@tripleee:实际上,当我用telnet粘贴时,我可以从smtp服务器获取邮件。 注意:在“。”后面最后,我离开了一次换行。 – balanv 2012-08-16 14:22:19

18
[[email protected] tmp]# mail -v [email protected] 
Subject: Test 
Hello world 
Cc: <Ctrl+D> 

[email protected] 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:<[email protected]> SIZE=46 
250 2.1.0 <[email protected]>... Sender ok 
>>> RCPT To:<[email protected]> 
>>> DATA 
250 2.1.5 <[email protected]>... Recipient ok 
354 Enter mail, end with "." on a line by itself 
>>> . 
250 2.0.0 q7NEneju002633 Message accepted for delivery 
[email protected] Sent (q7NEneju002633 Message accepted for delivery) 
Closing connection to [127.0.0.1] 
>>> QUIT 
221 2.0.0 piwik-dev.example.com closing connection 
20

关于使用telnet测试postfix或其他SMTP的唯一方法是必须知道命令和语法。相反,只需使用swaks :)

[email protected]:~$ 
[email protected]:~$ mail -f Maildir 
"/home/thufir/Maildir": 4 messages 
> 1 [email protected]     15/553 test Mon, 30 Dec 2013 10:15:12 -0800 
    2 [email protected]     15/581 test Mon, 30 Dec 2013 10:15:55 -0800 
    3 [email protected]     15/581 test Mon, 30 Dec 2013 10:29:57 -0800 
    4 [email protected]     15/581 test Mon, 30 Dec 2013 11:54:16 -0800 
? q 
Held 4 messages in /home/thufir/Maildir 
[email protected]:~$ 
[email protected]:~$ swaks --to [email protected] 
=== 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:<[email protected]> 
<- 250 2.1.0 Ok 
-> RCPT TO:<[email protected]> 
<- 250 2.1.5 Ok 
-> DATA 
<- 354 End data with <CR><LF>.<CR><LF> 
-> Date: Mon, 30 Dec 2013 14:33:17 -0800 
-> To: [email protected] 
-> From: [email protected] 
-> 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. 
[email protected]:~$ 
[email protected]:~$ mail -f Maildir 
"/home/thufir/Maildir": 5 messages 1 new 
    1 [email protected]     15/553 test Mon, 30 Dec 2013 10:15:12 -0800 
    2 [email protected]     15/581 test Mon, 30 Dec 2013 10:15:55 -0800 
    3 [email protected]     15/581 test Mon, 30 Dec 2013 10:29:57 -0800 
    4 [email protected]     15/581 test Mon, 30 Dec 2013 11:54:16 -0800 
>N 5 [email protected]     15/581 test Mon, 30 Dec 2013 14:33:17 -0800 
? 5 
Return-Path: <[email protected]> 
X-Original-To: [email protected] 
Delivered-To: [email protected] 
Received: from dur.bounceme.net (localhost [127.0.0.1]) 
    by dur.bounceme.net (Postfix) with ESMTP id 52D162C3EFF 
    for <[email protected]>; Mon, 30 Dec 2013 14:33:17 -0800 (PST) 
Date: Mon, 30 Dec 2013 14:33:17 -0800 
To: [email protected] 
From: [email protected] 
Subject: test Mon, 30 Dec 2013 14:33:17 -0800 
X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/ 
Message-Id: <[email protected]> 

This is a test mailing 

New mail has arrived. 
? q 
Held 5 messages in /home/thufir/Maildir 
[email protected]:~$ 

这只是一个简单的命令。

+1

我不知道swaks。谢谢! – 2015-01-14 19:28:57