segunda-feira, 28 de janeiro de 2013

Enviar email pela linha de comando

Instalar o pacote  mauilutils  para ter acesso ao comando  mail  no Debian

para enviar email com anexo:

# uuencode foto.jpeg | mail -s "titulo" endereço@email.com
Para configurar o debia para envio de email, usando o exim:

Install Exim and mailutils:
# apt-get -y install exim4-daemon-light mailutils

Run configurator:


# dpkg-reconfigure exim4-config

Select the following options:
  • General type of mail configuration: internet site; mail is sent and received directly using SMTP
  • System mail name: playground.localdomain
  • IP-addresses to listen on for incoming SMTP connections: 127.0.0.1 ; ::1
  • Other destinations for which mail is accepted: playground.localdomain; playground; localhost
  • The "Domains to relay mail for:" option is empty.
  • The "Machines to relay mail for:" option is empty.
  • Keep number of DNS-queries minimal (Dial-on-Demand)? 
  • Delivery method for local mail: Maildir format in home directory
  • Split configuration into small files?

Test Exim:

echo "Testing Exim" | mail -s Test 

If Exim does not deliver your messages, check that your provider does not block outgoing connections to 25 (SMTP) port by executing "telnet somedomain 25". Install the telnet package if it is not installed by executing "apt-get -y install telnet".
On some computers Exim displays Cannot open main log file "/var/log/exim4/mainlog": Permission denied error message when testing email sending. It can be solved by creating /var/log/exim4 folder as follows:

# mkdir -p /var/log/exim4
# chmod 740 /var/log/exim4 
# chown Debian-exim:adm /var/log/exim4
# touch /var/log/exim4/
# chown Debian-exim:adm /var/log/exim4/mainlog
Links
Send-only Mail Server with Exim