Preventing sendmail from been very slow
The first thing that I did after installing sendmail with
aptitude install sendmail
is I put “gate.localhost” (gate is my server name) to /etc/hosts so it looks like this:
127.0.0.1 localhost.localdomain localhost 127.0.1.1 gate.localhost gate # 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
With default /etc/hosts containing only “gate” and “localhost” sendmail hangs up for a while and writes to /var/log/mail.log the following message:
My unqualified host name (gate) unknown; sleeping for retry.
Testing
To test how sendmail works I used the following command:
/usr/sbin/sendmail -t -f myaddress@gmail.com -v -i < body.txt
Where body.txt is a text file containing the message body:
Subject: test mail to Some Address! From: Me <fromaddress@somemail.com> To: Vasya<toaddress@somemail.com> first line of my message
Please note, that without –f option provided in command line sendmail would not work, saying that there are some problems with the sender address.
Configuring SMTP server settings
To make sendmail work via my SMTP server I added SMART_HOST directive to sendmail.mc:
define(`SMART_HOST',`smtp.spbtlg.ru')dnl
Then I executed the following commands to changes take effect:
cd /etc/mail m4 sendmail.mc > sendmail.cf make /etc/init.d/sendmail restart
Fortunately, my SMTP server does not require any authorization so I do not need to use AuthInfo directive.
Configuring PHP mail() function
At last I put the following to /etc/php5/apache2/php.ini:
; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path sendmail_path = "/usr/sbin/sendmail -t -f myaddress@gmail.com -i"
Conclusion
I feel that there is another way, but looks like my php mail() function now works fine, at least I can receive messages from my websites.
Thank you!
Great!! It worked! Thanks a lot!
Works like a charm. Thanks.
While php expects to find a sendmail binary, that does not mean you should install the sendmail package. It’s a historical relic really, but part of its legacy is that there’s a standard path for a binary called sendmail with a standard interface which most mail software provides.
If it works for you, and since you’ve already installed sendmail, you might just leave it alone, but at the first hint of trouble (like your messing about with the sender address), you should switch to a modern mail program. My choice is postfix, but some people like exim or qmail, and of course there are many others less used.
sendmail has a configuration option to set which system users are allowed to set the sender address to something other than their system username at sendmail’s configured domain name. It’s been 10 years since I’ve needed this setting, so I can’t give it to you off the top of my head, but if you look for it you’ll find it.
The /etc/hosts settings are exactly what I needed for my dev-machine 🙂
Thank you for this article,
can you give more details about the use of “SMART_HOST” ?
Thanks for the post…
It helped me a lot…………
nice work
Thank you for this article. I do that, But not working in my server.
Please tell me what i do.
i get an error *** ERROR: FEATURE() should be before MAILER()
*** MAILER(`local’) must appear after FEATURE(`always_add_domain’)*** ERROR: FEATURE() should be before MAILER()
when i run
m4 sendmail.mc > sendmail.cf
Thanks it worked for me.
thank you this is worked…..nice job..!!
Thank you very much! It gives me a shot.
i dont know how to do this. can anyone explain to me step by step please?
Thank you