configurare exim per inviare email, servizio smtp di default su debian

le conf di default fatte dal dpkg-reconfigure, dovrebbero essere suff. in particolare usa "sito internet" e no fare il relay di nessun dominio

apt-get install exim4
dpkg-reconfigure exim4-config

dpkg farà alcune semplici domande la cui risposta di default funziona correttamente su un host con indirizzo fisso di cui ci interessi semplicemente l'invio delle email.

virtual server, invio diretto di posta:

internet site; mail is sent and received directly using SMTP
 
FQDN (fully qualified domain name) es. "www.mywebsite.com"
 
ip address to listen for SMTP connection: 127.0.0.1
 
Leave the relay domains and relay machines fields blank
 
Select "No" when asked whether to keep DNS queries to a minimum
 
"Maildir" when asked about the delivery method used for incoming mail
 
admin email in addition to "root" when asked to specify postmaster mail recipients: "root email@gmail.com"

test del funzionamento:

echo "some email body" | mail -s "a subject" test@gmail.com

Telnet Test session

telnet mail2.testserver.it 25
Trying 88.77.66.55...
Connected to mail2.testserver.it.
Escape character is '^]'.
220 mail2.testserver.it ESMTP Postfix
 
helo mysvr-hostname
250 mail2.testserver.it
 
mail from: <support@mysvr-hostname>
250 2.1.0 Ok
 
rcpt to: <testaddr@gmail.com>
250 2.1.5 Ok
 
data
354 End data with <CR><LF>.<CR><LF>
 
test1133
.
250 2.0.0 Ok: queued as 0F36DA0071
 
QUIT

Relay Exchange

server in rete che dispatchano su un server Exchange:

# assicurarsi che il server target risponda
telnet 192.168.1.x  25
seleziona: " mail sent by smarthost; no local mail "

Relay GMail

Send Messages through Gmail. (in alternativa inviare email con SMTP da PHP)

  • c'è un limite al numero di messaggi che invierà in un giorno(100 al giorno?)
  • Gmail rewriting your sender address or use this Gmail address.
sudo apt-get install exim4
sudo dpkg-reconfigure exim4-config
  1. mail sent by smarthost; no local mail
  2. System mail name: (default)
  3. IP-addresses to listen on for incoming SMTP connections: 127.0.0.1
  4. Other destinations for which mail is accepted: (default)
  5. Visible domain name for local users: yourdomain.com
  6. IP address or host name of the outgoing smarthost: smtp.gmail.com::587
  7. Keep number of DNS-queries minimal (Dial-on-Demand)? No
  8. Split configuration into small files? No

Submission port 587 on Gmail system uses STARTTLS service to ensure secure password protection.

Gmail provides SMTP under the name smtp.gmail.com. You can get the canonical host names of these servers by running:

$ host smtp.gmail.com
smtp.gmail.com is an alias for gmail-smtp-msa.l.google.com.
gmail-smtp-msa.l.google.com has address 74.125.127.109
gmail-smtp-msa.l.google.com has address 74.125.127.108
So gmail*.google.com matches all the real host names.

tell exim4 the username and password we are going to use:

sudo vi /etc/exim4/passwd.client
 
gmail-smtp.l.google.com:you@gmail.com:password
*.google.com:you@gmail.com:password
smtp.gmail.com:you@gmail.com:password

controllare i log

less /var/log/exim4/mainlog

make sure that you see a record with

R=smarthost T=remote_smtp_smarthost H=gmail-smtp-msa.l.google.com ... X=TLS-1.0:RSA_ARCFOUR_MD5:16

IP v6

If your emails are not able to leave the box and you're getting errors like this
2013-01-25 01:31:27 2TyWGU-0004ex-Hp IPv6 socket creation failed: Address family not supported by protocol
2013-01-25 01:31:27 2TyWGU-0004ex-Hp gmail-smtp-in.l.google.com [2a00:1450:4010:c03::1a] Address family not supported by protocol
2013-02-06 03:35:07 1U31bI-0005f3-Km ASPMX.L.GOOGLE.com [2607:f8b0:4001:c02::1b] Network is unreachable
2013-02-14 11:22:32 1U6t2I-0004Ne-OW ASPMX.L.GOOGLE.COM [2607:f8b0:4001:c02::1a] Connection timed out
it means that your network device has IPv6 enabled, but your network itself doesn't support it.

tell exim not to use IPv6 by adding the following to the top of your /etc/exim4.conf (or nano /etc/exim4/conf.d/main/02_exim4-config_options)

disable_ipv6=true

inviare un file di testo via email

mail -s "a subject" test@gmail.com < /var/log/apache2/error.log
 
echo "This is message body" | mail -s "subject" -a /path/to/file test@gmail.com

mailx SMTP

$ echo "This is the message body and contains the message" | mailx -v \
> -r "test@gmail.com" \
> -s "This is the subject" \
> -S smtp="mail.example.com:587" \
> -S smtp-use-starttls \
> -S smtp-auth=login \
> -S smtp-auth-user="test@gmail.com" \
> -S smtp-auth-password="abc123" \
> -S ssl-verify=ignore \
> yourfriend@gmail.com

inviare files via email da linea di comando

mpack -s subject file test@gmail.com

Set From:

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES

Very important, if you set this to NO (which seems to be the default) all your messages will be sent out as www-data@web.server and cannot be overridden by "From: " fields.

ref:

inviare dati per posta

echo "body of the mail" | mail -s "subject" test@gmail.com
# content from a file
mail -s "Hello world" test@gmail.com < /home/calvin/application.log

ricevere posta occorre unserver pop3. prova dovecot: utenti e permessi in mysql

Mail program

print(read): p  +   and  -   moving backwards and forwards, and simple numbers
delete:'d'
reply:'r'
exit:'x'
quit:'q'
Specifying messages:
list of message numbers:'delete 1 2' deletes messages 1 and 2,
'delete 1-5' deletes messages 1 through 5
'*': all messages
'$': last message
'top *': print all subjects

mail from command line

ssmtp can use a Gmail account as SMTP and send emails from the command line.

echo "Hello, User!" | mail user@domain.com

/etc/ssmtp/ssmtp.conf

root=***E-MAIL***
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=smtp.gmail.com:587
UseSTARTTLS=YES
UseTLS=YES
AuthUser=***E-MAIL***
AuthPass=***PASSWORD***
AuthMethod=LOGIN
FromLin

Encrypting Email with GPG

to send encrypted email messages. By encrypting the email message, you prevent sensitive data from passing over the network in the clear.

using GNU Privacy Guard (GPG) before sending it:

$message_body escapeshellarg($message_body);
$gpg_path     '/usr/local/bin/gpg';
$sender       'web@example.com';
$recipient    'ordertaker@example.com';
$home_dir     '/home/web';
$user_env     'web';

$cmd "echo $msg | HOME=$home_dir USER=$user_env $gpg_path " .
       
'--quiet --no-secmem-warning --encrypt --sign --armor ' .
       
"--recipient $recipient --local-user $sender";

$message_body = `$cmd`;

mail($recipient,'Web Site Order',$message_body);

Root email forward

sudo nano /etc/aliases
 
# add:
root: $user@gmail.com
 
newaliases
service postfix restart
# test root email
echo test | mail -s "test message" root