im trying to sent mail through php, in a Debian server with postfix, when i run the following script in the server, the code tells me that the email was sent successfully, This is my code:
<?php
$to = "themailtest@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Email successfully sent!</p>");
} else {
echo("<p>Email delivery failed¦</p>");
}
?>
But, when I check the mail of the recipient, is not in the inbox the mail that was sent. What files should I change in the configuration of postfix?
I post some of my configuration file of postfix:
-
/etc/postfix/main.cf
#See /usr/share/postfix/main.cf.dist for a commented, more complete version #Debian specific: Specifying a file name will cause the first #line of that file to be used as the name. The Debian default #is /etc/mailname. #myorigin = /etc/mailname smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) biff = no #appending .domain is the MUA's job. append_dot_mydomain = no #Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = /usr/share/doc/postfix #TLS parameters smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache #See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for #information on enabling SSL in the smtp client. myhostname = simbiosis_ucv alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases mydestination = simbiosis_ucv, localhost.localdomain, , localhost relayhost = [gmail-smtp-msa.l.google.com]:587 mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all html_directory = /usr/share/doc/postfix/html smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd smtp_sasl_security_options = noanonymous smtp_use_tls = yes smtp_tls_CAfile = /etc/postfix/cacert.pem
-
/etc/hosts
127.0.0.1 localhost 190.169.94.56 tesisvergaraomana tesisvergaraomana The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
-
/var/log/mail.log
Apr 5 16:21:27 tesisvergaraomana postfix/smtp[10172]: 3427C22E015: to= <javiervergara2004@gmail.com>, relay=gmail-smtp-msa.l.google.com[74.125.196.109]:587, delay=0.54, delays=0.1/0.01/0.37/0.07, dsn=5.7.0, status=bounced (host gmail-smtp-msa.l.google.com[74.125.196.109] said: 530 5.7.0 Must issue a STARTTLS command first. t9sm11828331yhg.18 - gsmtp (in reply to MAIL FROM command)) Apr 5 16:21:27 tesisvergaraomana postfix/cleanup[10157]: CD71422E016: message-id=<20140405205127.CD71422E016@simbiosis_ucv> Apr 5 16:21:27 tesisvergaraomana postfix/bounce[10173]: 3427C22E015: sender non-delivery notification: CD71422E016 Apr 5 16:21:27 tesisvergaraomana postfix/qmgr[25492]: CD71422E016: from=<>, size=2403, nrcpt=1 (queue active) Apr 5 16:21:27 tesisvergaraomana postfix/qmgr[25492]: 3427C22E015: removed Apr 5 16:21:27 tesisvergaraomana postfix/local[10159]: CD71422E016: to=<root@simbiosis_ucv>, relay=local, delay=0.11, delays=0.05/0/0/0.06, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION") Apr 5 16:21:27 tesisvergaraomana postfix/qmgr[25492]: CD71422E016: removed Apr 5 16:39:01 tesisvergaraomana postfix/pickup[10185]: BB34622E016: uid=0 from=<root> Apr 5 16:39:01 tesisvergaraomana postfix/cleanup[10333]: BB34622E016: message-id=<20140405210901.BB34622E016@simbiosis_ucv> Apr 5 16:39:01 tesisvergaraomana postfix/qmgr[25492]: BB34622E016: from=<root@simbiosis_ucv>, size=785, nrcpt=1 (queue active) Apr 5 16:39:01 tesisvergaraomana postfix/local[10335]: BB34622E016: to=<root@simbiosis_ucv>, orig_to=<root>, relay=local, delay=0.2, delays=0.13/0/0/0.06, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION") Apr 5 16:39:01 tesisvergaraomana postfix/qmgr[25492]: BB34622E016: removed Apr 5 16:40:01 tesisvergaraomana postfix/pickup[10185]: D29A222E016: uid=104 from=<smmsp> Apr 5 16:40:01 tesisvergaraomana postfix/cleanup[10333]: D29A222E016: message-id=<20140405211001.D29A222E016@simbiosis_ucv> Apr 5 16:40:01 tesisvergaraomana postfix/qmgr[25492]: D29A222E016: from=<smmsp@simbiosis_ucv>, size=696, nrcpt=1 (queue active) Apr 5 16:40:01 tesisvergaraomana postfix/local[10335]: D29A222E016: to=<root@simbiosis_ucv>, orig_to=<root>, relay=local, delay=0.19, delays=0.13/0/0/0.06, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION") Apr 5 16:40:01 tesisvergaraomana postfix/qmgr[25492]: D29A222E016: removed
-
/etc/resolv.conf
nameserver 190.169.94.5
-
postconf -n
alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases append_dot_mydomain = no biff = no config_directory = /etc/postfix html_directory = /usr/share/doc/postfix/html inet_interfaces = all mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 mydestination = simbiosis_ucv, localhost.localdomain, , localhost myhostname = simbiosis_ucv mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 readme_directory = /usr/share/doc/postfix recipient_delimiter = + relayhost = [gmail-smtp-msa.l.google.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_tls_session_cache_database = btree:${data_directory}/smtp_scache smtp_use_tls = yes smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtpd_use_tls = yes
My goal is to get a full functionaly mail server, and it can send email to all address
host: strix.ciens.ucv.ve
port: 465
domain: ciens.ucv.ve
username: mail.test@ciens.ucv.ve
active ssl
Can anyone point me to what to change in the configuration?. I need to install another tool?I hope that's all. If you need something else, let me know.
Best Answer
Based on the log entry:
Apparently something is wrong with you tls configuration.
First of all, you should setup a "proper" certificate. How to do that for a self signed certificate, you can check here e.g.: create postfix certificate
Then you use configuration option:
If you look that up the documentation reveals the following:
Documentation for
smtp_tls_security_level
you can look up here: http://www.postfix.org/postconf.5.html#smtp_tls_security_level(I have to admit that I personally use the option
smtpd_use_tls = yes
with a self-signed-certificate without any troubles)You can find more info here about postfix and tls here: http://www.postfix.org/TLS_README.html
Additionally it seems you are working with a relay host (
relayhost = [gmail-smtp-msa.l.google.com]:587
). Which means that all mail you send is routed through the relay-host. In most cases the port 587 can only be accessed with a proper tls connection. Therfore you need a working tls setup and if you need to authenticate on the google relayhost, you have to set-up additional configuration-options.Take a look here for that: http://baldric.net/upstream-authentication-with-tls-on-postfix/
Furthermore you have also to verify that postfix has access to all the necessary files. I did not use Debian for quite a time, but afaik it runs or ran in a
chroot
ed environment in Debian. So make sure all necessary files are reachable for postfix (in your case basically the configuration files, certificates and caches).I'll hope this points you in the right direction. Good luck. :)