Koozali.org: home of the SME Server

qmHandle, how to list emails in queue

Offline Tillebeck

  • ****
  • 76
  • +0/-0
qmHandle, how to list emails in queue
« on: May 08, 2008, 05:08:30 PM »
Hi
I got a call that our server is sending SPAM. I is either a
 - web apllication on the server
 - a client PC (winxp) on the network...

better try to monitor it.

I installed the qmHandle and stopped the qmail
Code: [Select]
service qmail stopNow emails are slowly builing up in the queue.

But how do I see from who or to who theese emails are for?
Doing the qmHandle-s, qmHandle-l, qmHandle-L all return:
Code: [Select]
Total messages: 55
Messages with local recipients: 0
Messages with remote recipients: 0
Messages with bounces: 0
Messages in preprocess: 55

Any way to find out witch web application (if any) is sending out mails?

Thanks,
Anders

Offline Normando

  • *
  • 841
  • +2/-1
    • Unixlan
Re: qmHandle, how to list emails in queue
« Reply #1 on: May 08, 2008, 06:30:49 PM »
This is not the correct way to stop qmail! Because hang
SME server is a little different compared with other linux distributions.

You have an entirelly wiki page about qmHandle:

http://wiki.contribs.org/Qmhandle_mail_queue_manager

To begin a quick investigation, rename your ibays html folder to htmlb.
Also rename the /opt/xxx folders if your have some scripts under /opt dir.

Wait a few hours and look If you have a lot of emails into queue. If yes, then your sites are ok, restore the name of your html dirs.
So, the problem is a machine in your local network.

Authenticate smtp for local network:

http://wiki.contribs.org/Email#How_do_I_enable_smtp_authentication_for_users_on_the_internal_network.
http://wiki.contribs.org/Email#How_do_I_disable_SMTP_relay_for_unauthenticated_LAN_clients

Offline Tillebeck

  • ****
  • 76
  • +0/-0
Re: qmHandle, how to list emails in queue
« Reply #2 on: May 08, 2008, 09:52:03 PM »
Hi Normando

Thanks for your reply.

Web app. sending mail:
Renaming the html folders should definetely show me if any app is sending mails. Thanks for that tip. I will do that after a short notice to the users.

qmHandle
I had seen the wiki for the qmHandle. The problem is that each command for listing output returns the same result. I do not know if this is normal or it is a sign that the server has been infected. Or maybe that I stopped the qmail the wrong way.
  - thanks for pointing that out by the way. I do see now that the wiki also gives away how to stop and start the qmail the proper way:
Code: [Select]
sv d /service/qmail (this will stop qmail)
sv u /service/qmail (this will start qmail again)

The qmHandle wiki page gives some commands for listing mails and for deleting mails. I want to list the mails. At least three of these four commands should list mails I believe:
Code: [Select]
qmHandle -l       : list message queues
qmHandle -L       : list local message queue
qmHandle -R       : list remote message queue
qmHandle -s       : show some statistics

...but I get the same result for all four commands as shown in the code block here below. I guess it is the statistics result I get from them all four. That cannot be correct, can it? I am confused:
Code: [Select]
[root@ronja ~]# qmHandle -L
Total messages: 569
Messages with local recipients: 0
Messages with remote recipients: 0
Messages with bounces: 0
Messages in preprocess: 569
[root@ronja ~]#

This next command should list all the messages in the queue counting the number of messages with the same subject. When executed the command is accepted but there is no result. Here is the command executed and the empty result:
Code: [Select]
[root@ronja ~]# qmHandle -l|grep Subject|sort| uniq -c|sort -n
[root@ronja ~]#

I really really really would like to know how to find out who the mails are from and who the recipients are. Can I look into a folder somewhere and have a look at the queue? Is qmHandle acting strange (or maybe my server is acting strange)?

Email settings for users
Thanks for the tip with setting up the smtp authentication and unauthenticated mail relay for local networks. I have not done it before since I have quite a few applications sending out mail. Will they still be able to send mails? Or shall those applications then also connect to localhost with a user/password? I do see some big advantages in this. Then each web application can have there own user. Then any future compromized application will be easy to stop sending spam just by disappling there sme user


I really hope for a reply on how to examine the mail queue.

BR. Anders
Thanks for any help provided.

Offline Tillebeck

  • ****
  • 76
  • +0/-0
Re: qmHandle, how to list emails in queue
« Reply #3 on: May 08, 2008, 09:54:09 PM »
one more question...
...instead of remaning all the html folders to html_something. Wouldn't it give same result just to kill the web server?

 -- anders

Offline Tillebeck

  • ****
  • 76
  • +0/-0
Re: qmHandle, how to list emails in queue [SOLVED]
« Reply #4 on: May 08, 2008, 10:26:30 PM »
Confusion is complete. But problem is solved.

After a reboot of the server the qmHandle works as a charm and makes nice lists of mails in the queue when running the commands listed in my previous posts

The problem can have been caused by one of these two reasons:
 - I did not stop the qmail using the correct SME command (i just did a service stop)
 - I did not restart the entire server after installing the qmHandle (the wiki said that a reconfigure and reboot was not required)

Problem is solved. Now it is time for analyzing the queue.

BR. Anders

Offline Normando

  • *
  • 841
  • +2/-1
    • Unixlan
Re: qmHandle, how to list emails in queue
« Reply #5 on: May 08, 2008, 10:27:14 PM »
You have the same results because you was stop qmail in the wrong way, so, restart your server complete. Then delete your queue.
Remember, before delete your queue (qmHandle -D) stop qmail, then start it again with the correct command.

Of course, you can stop e-smith-httpd service with "sv d httpd-e-smith". Use "sv u httpd-e-smith" to start again, or "sv t httpd-e-smith" to restart.

I was have the same issue, with 41000 message in the queue every day! And I was found an infected worksation. When implement smtp authentication, the problem was fixed.

It is important to made some captcha image verification if you have a web application to send email, to avoid bot spam. Also you can modify you application to use an user and password to authenticate with your localhost smtp.

A question: I was looked your command prompt [root@ronja ~]#
You are the same man from http://ronja.twibright.com/ ?

Offline Tillebeck

  • ****
  • 76
  • +0/-0
Re: qmHandle, how to list emails in queue
« Reply #6 on: May 08, 2008, 11:54:54 PM »
Captcha are beeing used - or similar. So if a web app are the sender then it must have been hacked or compromized in some way. I guess it is a workstation though... But we'll see.

Ronja is my daughter. since I bought that specific server I got to name it. And I name servers like most people choose passwords ;-) But about a year ago I actually did read about the Ronja project from Twibright. Super cool to build your own data link - or just shoot some birds from the sky.

Btw. I started a new thread on how to delete SPAM mails before it is send out from the server. Feel free to join in:
http://forums.contribs.org/index.php?topic=40965

Cheers, Anders

Offline Normando

  • *
  • 841
  • +2/-1
    • Unixlan
Re: qmHandle, how to list emails in queue
« Reply #7 on: May 09, 2008, 12:01:47 AM »
or just shoot some birds from the sky.
:lol: :lol: :lol:

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: qmHandle, how to list emails in queue
« Reply #8 on: May 09, 2008, 03:27:02 AM »
This is not the correct way to stop qmail!

No, that will do fine. That will do the same as "sv u /service/qmail".

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: qmHandle, how to list emails in queue
« Reply #9 on: May 09, 2008, 03:31:36 AM »
I really really really would like to know how to find out who the mails are from and who the recipients are.

You can find out who they *claim* to be from (the sender address of spam and virus messages is always forged), and who they are to, via:

/var/qmail/bin/qmail-qread

« Last Edit: May 09, 2008, 03:39:54 AM by CharlieBrady »

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: qmHandle, how to list emails in queue
« Reply #10 on: May 09, 2008, 03:38:13 AM »
Any way to find out witch web application (if any) is sending out mails?

You can find out whether the messages are being sent by a PC on the LAN or by a web application by carefully reading the full headers of any of the messages. If it is a web application sending the messages, you will see the uid of 'www' as the sender which injected the message. But you won't be able to tell which web application it is by that technique.

Offline Normando

  • *
  • 841
  • +2/-1
    • Unixlan
Re: qmHandle, how to list emails in queue
« Reply #11 on: May 09, 2008, 05:29:38 AM »
No, that will do fine. That will do the same as "sv u /service/qmail".

Can you explain me why exist inconsistences between explanations?

tias_
I'm sure you need to stop qmail BEFORE you flush the queue !

It has been said so many times in these forums, for the last three years or so, NOT to use the service command as it does not always do everything that is required in sme server. sme is a bit different to other Linux distros.
sme7.x uses supervised services which will automatically restart if they stop and uses the sv command
ie
to bring down
sv d /service/qmail
to bring up
sv u /service/qmail
to terminate (which forces a restart due to being a supervised service)
sv t /service/qmail

For any non supervised service use
/etc/init.d/servicename restart (or stop or start or status)

See the developer manual for more details


When I was tried stoping qmail with "service qmail stop" and then starting with "service qmail start" never run again, and I needed to reboot the server.

I think to make or expand a wiki page with the correct way to handle the services, one by one.

Offline Tillebeck

  • ****
  • 76
  • +0/-0
Re: qmHandle, how to list emails in queue
« Reply #12 on: May 09, 2008, 02:23:04 PM »
Ok. I start to realize that I asked the wrong question. I started this thread to figure out why I could not get qmHandle to list messages. It seems I just did not understand how qmail works and what qmHandle does.

Many post write that before using qmHandle the qmail should be stopped. This must be a thruth with modification. I guess it is correct that qmail shold be stopped before the queue is manipulated in any way. But for pure statistics and listings then qmail needs to run. Otherwise mails will stay in the "Preprocess queue" and not be sorted into either the "Local" or the "Remote" queue.

So this result is just fine since qmail had not been running while the mails had been build up in the queue
Code: [Select]
[root@ronja ~]# qmHandle -L
Total messages: 569
Messages with local recipients: 0
Messages with remote recipients: 0
Messages with bounces: 0
Messages in preprocess: 569
[root@ronja ~]#

The question I should have asked was:
How do I stop my server (qmail?) from sending mails from the local or remote queue?

As it is now when mails are processed by qmail and they end up in the local or remote queue then they are send out into the internet in a split second. I would like qmail not to send out mails but to run and to sort the mails into the to queues so gmHandle can list them. Also the command given by Charlie Brady that list who mails *claim* to be from:
Code: [Select]
/var/qmail/bin/qmail-qread(great command, Charlie, thanks for posting it)


BR. Anders

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: qmHandle, how to list emails in queue
« Reply #13 on: May 09, 2008, 03:46:59 PM »
Can you explain me why exist inconsistences between explanations?

People used the "service" command so frequently that we added "/sbin/e-smith/service". "/sbin/e-smith/service" will do "the right thing". "/sbin/service" often does not. Just typing "service" will execute "/sbin/e-smith/service".

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: qmHandle, how to list emails in queue
« Reply #14 on: May 09, 2008, 03:49:47 PM »
The question I should have asked was:
How do I stop my server (qmail?) from sending mails from the local or remote queue?

You stop it. If you want it to run, but not send mails remotely, you will need to bring down your WAN link.

But I'd ask what problem you are actually trying to solve. You should be able to work out yourself visually which messages have local recipients and which have remote recipients.