Page 1 of 1

Hesk mail not working even though mail works from the server

Posted: Thu Feb 05, 2015 7:10 pm
by bhall
Script URL:
Version of script:
Hosting company: self hosted
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution: "mail not sending" "email not working"

Write your message below:

Me again (from the other ticket where I was getting a blank page from /hesk/install). Anyway, now I've get the re-install of hesk (after our old server crashed) back up and running fine with everything working EXCEPT email notifications.

In the past I've just used the PHP Mail () option and it has always worked (after our very first setup several years ago when I had to whitelist our mail server in our SPAM filter, but other than that initial issue years ago, it has always worked).

New server, new install of Hesk 255, same network settings, same SPAM filter settings, but with this fresh install the notifications are not being sent.

The server is CentOS 6.3 and is using the default install of Postfix MTA. If I send mail from the command line on the linux Hesk server using:

mail -s "Hello" my@email.address
CTL-D

the message arrives in my work email inbox just fine.

If, on the linux/hesk server, I go do the directory /usr/sbin and issue the command:

sendmail my@email.address
Hi
CTL-D

the message arrives in my inbox just fine.

So, I know that the server that is hosting Hesk is able to send mail successfully, and that it is being received. I can see this email in my SPAM filter logs as being allowed for the reason of "whitelist" since I've whitelisted the Hesk server. When I submit a test ticket through Hesk, there are no records of any email in our SPAM filter logs even making it to the SPAM filter from the Hesk server, and no messages are received.

I've checked the Php.ini file's mail section and the path for mail is correctly listed as /usr/sbin/sendmail

When a new ticket is created by a user, they do not receive a notification, and none of the tech staff who have accounts in Hesk receive any notification.

Again, this is probably my 4th Hesk install, and I've never had this issue previously. I've successfully tested email sending from the Hesk server by command line, and I've verified that the Php.ini file is looking in the right place. I'm not sure what to try next.

Re: Hesk mail not working even though mail works from the se

Posted: Thu Feb 05, 2015 7:39 pm
by Klemen
The trick is to get PHP mail() function to work, not mail/sendmail from the command line.

HESK doesn't do the actual sending, it's PHP that does that. HESK just passes the arguments to the PHP function.

Example PHP file to test:

Code: Select all

<?php
mail('you@yourdomain.com', 'Test', 'Test');
echo "Mail sent";
?>
For a direct HESK delivery try using a real email account instead and set HESK settings to "Send mail using: SMTP server", as suggested here:
http://www.hesk.com/knowledgebase/index.php?article=25

Re: Hesk mail not working even though mail works from the se

Posted: Thu Feb 05, 2015 7:55 pm
by bhall
For the example PHP file, do I just create a file and save it as a .php extension and then open it in a browser directly to that file?

Example: create testmail.php with pasted content you provided, put it inside /hesk folder, then open
/hesk/testmail.php

Will that test the php mail functionality, or is there another step?

As far as using SMTP server, I've tried that and I get "access is denied" no matter how I configure it (with account, without one, etc). I do have a receive connector on my Exchange server for Hesk to allow mail from the server. I use this same setup with other products (barracuda, POS systems, firewall, etc.) and it works OK on those, but when I use SMTP in Hesk, I always get access denied. The servers are on the same local subnet and there are no firewalls in between.

Re: Hesk mail not working even though mail works from the se

Posted: Thu Feb 05, 2015 7:58 pm
by Klemen
Yes, just save as a .php file (add your email address in the code, of course) and open in browser.

What exact error do you get using SMTP (the entire error log)?

Re: Hesk mail not working even though mail works from the se

Posted: Thu Feb 05, 2015 8:11 pm
by bhall
Ok, info on both PHP attempt and SMTP attempt:

1. PHP TEST FILE: I created a file called testmail.php with the included code and used my email address in place of you@yourdomain.com.

I saved that file in the apache root folder, then browsed to hesk.gccc.local/testmail.php with a browser. I do not get an error, but just a blank white page. No email is received.


2. SMTP TEST: When I add my email server to the SMTP settings I get (address replaced with x's):

Error: Could not connect to the host "x.x.x.x": Permission denied
Connecting to host address "x.x.x.x" port 25...


I get this without a username, and I get it with a username. With the other devices I mentioned (firewall, barracuda, etc.) I do not use a username and mail is sent from those devices just fine to the same server.

Re: Hesk mail not working even though mail works from the se

Posted: Thu Feb 05, 2015 8:29 pm
by Klemen
1. This is the simplest possible code for PHP mail(). If this doesn't work then your PHP cannot send out emails.

2. It doesn't look like a firewall-related problem, connection would timeout if it was that. It appears that Exchange is actively refusing the connection due to a, you guessed it, permissions issue. Exchange logs would be the next place to look for clues.


All in all, both #1 and #2 boil down to server configuration issues. Unfortunately without a "hands on" approach I can't be of much help as I have no idea how your server(s) are setup. It's just wild guesses.

Re: Hesk mail not working even though mail works from the se

Posted: Thu Feb 05, 2015 8:31 pm
by Klemen
P.s. if you are by any chance using SELinux it seems to be a common issue for failed connections to exchange.

Re: Hesk mail not working even though mail works from the se

Posted: Thu Feb 05, 2015 9:06 pm
by bhall
I'm not seeing anything in my Exchange logs. No dropped connections or anything. I don't have SELinux on this server, and the IPTables firewall is disabled.

I checked the maillog on the Linux server and found something odd. Here's the log of a message manually sent form the command line:

Code: Select all

Feb  5 15:46:19 hesk postfix/pickup[3550]: D5B4921869: uid=0 from=<root>
Feb  5 15:46:19 hesk postfix/cleanup[4687]: D5B4921869: message-id=<20150205204619.D5B4921869@hesk.gccc.local>
Feb  5 15:46:19 hesk postfix/qmgr[2174]: D5B4921869: from=<root@hesk.gccc.local>, size=429, nrcpt=1 (queue active)
Feb  5 15:46:20 hesk postfix/smtp[4689]: D5B4921869: to=<bhall@greeneccc.com>, relay=mail.greeneccc.com[66.161.176.98]:25, delay=0.21, delays=0.1/0.01/0.06/0.05, dsn=2.0.0, status=sent (250 Ok: queued as CD62A9406C5)
Feb  5 15:46:20 hesk postfix/qmgr[2174]: D5B4921869: removed
and here's text from the log when I use the testmail.php file you had me create:

Code: Select all

Feb  5 14:51:19 hesk postfix/pickup[3101]: 806C321869: uid=0 from=<root>
Feb  5 14:51:19 hesk postfix/cleanup[3118]: 806C321869: message-id=<20150205190119.806C321869@hesk.gccc.local>
Feb  5 14:51:19 hesk postfix/qmgr[2174]: 806C321869: from=<root@hesk.gccc.local>, size=283, nrcpt=1 (queue active)
Feb  5 14:51:19 hesk postfix/smtp[3120]: 806C321869: to=<bhall@greeneccc.com>, relay=mail.greeneccc.com[66.161.176.98]:25, delay=4.6, delays=4.5/0.01/0.06/0.05, dsn=2.0.0, status=sent (250 Ok: queued as 5F9A59406C5)
Feb  5 14:51:19 hesk postfix/qmgr[2174]: 806C321869: removed
Feb  5 14:56:45 hesk postfix/sendmail[3199]: fatal: chdir /var/spool/postfix: Permission denied
Feb  5 14:56:45 hesk postfix/sendmail[3200]: fatal: chdir /var/spool/postfix: Permission denied
Feb  5 14:58:35 hesk postfix/sendmail[3326]: fatal: chdir /var/spool/postfix: Permission denied
Feb  5 14:58:58 hesk postfix/sendmail[3327]: fatal: chdir /var/spool/postfix: Permission denied
What's strange is that unless I'm missing something, the actual mail send says status-sent OK for both, but only the one that was done manually is actually being sent. The errors after the second entry came a little later, so I'm not sure they're related.

Re: Hesk mail not working even though mail works from the se

Posted: Thu Feb 05, 2015 9:16 pm
by Klemen

Re: Hesk mail not working even though mail works from the se

Posted: Thu Feb 05, 2015 10:04 pm
by bhall
Klemen wrote:Why not Google the error?
Actually, I did google the error immediately after I posted the last message and I found the solution, but I only had time to try it quickly before leaving for the day. I'm just now getting to update since I just got home from work.

So, I found another forum where someone was getting the same error. They suggested running the following command:

/usr/sbin/getsebool httpd_can_sendmail

My response was httpd_can_sendmail --> off

I then ran:

/usr/sbin/setsebool httpd_can_sendmail 1

I created a new ticket and notifications are now working. Apparently there is a modified version of that command that has to be run to make the change permanent, but I didn't have time to do that before leaving, so I'll figure that last step to make it's permanent first thing in the morning.

The odd thing is that this is the exact same CentOS disk I used before for my last Hesk install, and I set it all up the same way I did before, so I'm not sure why this worked differently this time. I definitely didn't have this mail issue previously and I never messed with php mail settings, httpd settings, or postfix settings. Oh well, I'm just glad I found the answer and that I learned something new today, and I hope this may be helpful to anyone else who comes here with a similar issue.

Re: Hesk mail not working even though mail works from the se

Posted: Fri Feb 06, 2015 7:08 am
by Klemen
Adding -P to the command should make it permanent:

Code: Select all

/usr/sbin/setsebool -P httpd_can_sendmail 1
Glad you got it working :wink: