Estou tentando enviar e-mail a partir da linha de comando do meu servidor ubuntu. Então comecei a configurar o postfix na minha máquina local e não no servidor. Então, basicamente, essas são as etapas que segui:
sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
sudo vim /etc/postfix/main.cf
Adicionadas linhas abaixo no arquivo:
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
sudo vim /etc/postfix/sasl_passwd
Adicionada esta linha no arquivo [smtp.gmail.com]:587 [email protected]:PASSWORD
Permissões e atualizou o arquivo de configuração do postfix.
sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
recarregue o POSTFIX: sudo /etc/init.d/postfix reload
Então, no meu terminal, eu corro este comando:
echo "Test mail from postfix" | mail -s "Test Postfix" [email protected]
Mas não recebeu o email. Então eu verifiquei o arquivo de log e é aí que eu encontrei o rastreamento de pilha abaixo para ele:
postfix/pickup[26530]: A62AF2E29B4: uid=1000 from=<z@mylaptop>
postfix/cleanup[27372]: A62AF2E29B4: message-id=<20160428114754.A62AF2E29B4@mylaptop>
postfix/qmgr[26529]: A62AF2E29B4: from=<z@mylaptop>, size=365, nrcpt=1 (queue active)
postfix/smtp[27379]: cannot load Certificate Authority data: disabling TLS support
postfix/smtp[27379]: warning: TLS library problem: error:02001002:system library:fopen:No such file or directory:bss_file.c:169:fopen('/etc/postfix/cacert.pem','r'):
postfix/smtp[27379]: warning: TLS library problem: error:2006D080:BIO routines:BIO_new_file:no such file:bss_file.c:172:
postfix/smtp[27379]: warning: TLS library problem: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib:by_file.c:274:
postfix/smtp[27379]: connect to smtp.gmail.com[2404:6800:4003:c02::6d]:587: Network is unreachable
postfix/smtp[27379]: A62AF2E29B4: to=<[email protected]>, relay=smtp.gmail.com[74.125.68.108]:587, delay=1.4, delays=0.01/0.02/1/0.34, dsn=5.7.0, status=bounced (host smtp.gmail.com[74.125.68.108] said: 530 5.7.0 Must issue a STARTTLS command first. g70sm14489231pfb.7 - gsmtp (in reply to MAIL FROM command))
postfix/cleanup[27372]: 5BFDF2E2B48: message-id=<20160428114756.5BFDF2E2B48@mylaptop>
postfix/bounce[27383]: A62AF2E29B4: sender non-delivery notification: 5BFDF2E2B48
postfix/qmgr[26529]: 5BFDF2E2B48: from=<>, size=2239, nrcpt=1 (queue active)
postfix/qmgr[26529]: A62AF2E29B4: removed
postfix/local[27384]: 5BFDF2E2B48: to=<z@mylaptop>, relay=local, delay=0.01, delays=0/0.01/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
postfix/qmgr[26529]: 5BFDF2E2B48: removed