2012-08-16 1 views
95

Ho un server SMTP, ai fini di questa domanda lo chiamiamo: smtp.mydomain.com.Come verificare se smtp sta funzionando da commandline (Linux)

Come posso controllare se il server SMTP è in funzione? Posso inviare e-mail dalla linea di comando di Linux?

+0

@Flexo Queste domande non dovrebbero essere migrate anziché chiuse? Sembra che appartenga a Serverfault – Balmipour

+1

@Balmipour le vecchie domande non possono essere migrate, anche dai moderatori. Ci sono buone ragioni per questo discusso su http://meta.stackexchange.com (non ho un collegamento a portata di mano in questo momento), ma nota che la domanda non viene cancellata. – Flexo

+0

Dopo aver controllato diversi post su Meta, sembra (per me) che la migrazione di "solo" debba riaprire prima. Forse questo non è possibile con vecchie domande, btw. Immagino che tu lo sappia meglio di me. Comunque, grazie per la tua risposta. Un punto più rilevante che ho letto nei meta post è che la migrazione sembra richiedere una domanda "particolarmente preziosa". Non che questo sia inutile, ma neanche un gioiello. Non capisco molto, dato che SO è sopravvalutato su altri siti come ServerFault/Linux o Superuser, ma terrò il dibattito per un altro giorno (e appartiene comunque a Meta, non SO :) – Balmipour

risposta

125

Telnet al server SMTP come

telnet smtp.mydomain.com 25 

Sintassi:

telnet {smtp_domain_name} {port_number} 

E copiare e incollare il seguito

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 
. 

Nota: "" Non dimenticate il alla fine che rappresenta la fine del messaggio

L'ho trovato sul web e l'ho aggiunto a Stack Overflow come molti finiscono qui.

+5

Dovresti aspettare la risposta del server a ciascun comando e interrompi se ottieni ed errore (codice risultato 4xx o 5xx). – tripleee

+1

Hai bisogno di una linea vuota tra intestazioni e messaggio, a parte frammento che è un esempio funzionante. – martineg

+1

@ triple: in realtà quando ho incollato questo in telnet, posso ottenere e-mail dal server smtp. Nota: Afte il "." alla fine, ho lasciato un'interruzione di linea. – balanv

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

L'unica cosa sull'utilizzo di telnet per testare postfix o altri SMTP, è che devi conoscere i comandi e la sintassi. Invece, basta usare swaks :)

[email protected]:~$ 
[email protected]:~$ mail -f Maildir 
"/home/thufir/Maildir": 4 messages 
> 1 [email protected].bouncem     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]:~$ 

È solo un comando facile.

+1

Non sapevo di swaks. Grazie! –