Feb 292012
 

Un po’ vecchio, ma questo post è ancora davvero utile, ho usato questo metodo recentemente su un server.Articolo di Tom, prima pubblicato su Tombuntu

Non sarebbe utile se il computer potesse scrivervi ? Vorrei ricevere una notifica via email quando il mio server è in difficoltà, ma non voglio avere un mio server di posta. sSMTP è perfetto per questo: è un modo semplice per inviare e-mail dal proprio sistema ad un server di posta SMTP, come Gmail.

Ecco come ho configurato sSMTP su Ubuntu per inviare posta attraverso il mio account Gmail.


Installate sSMTP dal pacchetto ssmtp (clicca sul link per l’installazione su Debian/Ubuntu), oppure eseguendo il seguente comando nel terminale:
sudo apt-get install ssmtp

sSMTP può essere configurato da un file di testo. Aprite /etc/ssmtp/ssmtp.conf in un editor di testo:
sudo gedit /etc/ssmtp/ssmtp.conf

Il file di configurazione è molto breve e ben commentato. Ecco le opzioni che uso per l’invio di posta tramite Gmail:
[email protected]
mailhub=smtp.gmail.com:587
AuthUser=mygmailusername
AuthPass=mypassword
UseSTARTTLS=YES
UseTLS=YES
AuthMethod=LOGIN # Questo serve per Gmail

Se si utilizza Gmail come me, cambiare le opzioni root, authuser, e authpass con l’indirizzo e-mail, il nome utente e la password del vostro account Google. Se state usando un altro servizio di posta avrete bisogno di cambiare mailhub per il server SMTP in questione.

Una volta che il lavoro di configurazione è fatto, bisognai provare l’invio di alcune mail! Il modo più semplice per farlo è quello di eseguire ssmtp in un terminale con un indirizzo e-mail destinatario:

ssmtp [email protected]

sSMTP quindi attenderà che voi scriviate il vostro messaggio, che deve essere formattato in questo modo:
To: [email protected]
From: [email protected]
Subject: test email

hello world!

Notare la riga vuota come dopo il soggetto, tutto dopo questa linea è il corpo del messaggio. Quando avete finito, premete Ctrl-D. ssmtp può richiedere alcuni secondi per inviare il messaggio prima della chiusura.

Ora è facile scrivere script che inviano la posta. Ecco un comando di esempio da terminale per inviare un’e-mail dal file di testo msg.txt:

ssmtp [email protected] < msg.txt

msg.txt is a simple text using the proper formatting for sSMTP:
To: [email protected]
From: [email protected]
Subject: alert

Il server è down!

Popular Posts:

Flattr this!

  5 Responses to “Mandare email dal vostro sistema Linux con sSMTP”

  1. I use http://freecode.com/projects/sendemail that works great.
    Try it!

  2. @Rickyx.. Yeah I’m using sendEmail too… that is very easy to use

  3. hi! I’m trying with my mail server on other lan host,so it’s not gmail but It not work 🙁 it said that our server not support auth login with error 502.2.2.

  4. ODIO SENDMAIL. Non esiste una cakkio di guida decente che spieghi in maniera semplice come cakkio inviare una fottutissima email da terminale. Devo partire tra due giorni e non me ne sbatte niente della storia di sendmail. E non funziona. Maledetta filosofia per cui uno deve per forza avere problemi prima di poter usare un programma, o capirne per forza il funzionamento intrinseco. Doverlo fare per forza è l’equivalente del non poterlo fare.
    GRAZIE per questo post. 2 minuti e tutto funziona…. grazie grazie grazie.
    E quando avrò 10 ore libere mi leggerò pure il manuale del maledetto sendmail!

  5. This is the shortest and simplest way to send mail. You saved me after 2 days of fighting with postfix and sendmail (wondering why they make them that complicated). I had scrolled through long pages of tutorials then came here only to find no scrolling is needed. Thanks a lot.

    David, Uganda

Leave a Reply to Riccardo Cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*