Question

How to delete spam emails using qmHandle?

Asked by: testez

Hello,

I would like to know how to delete the emails originating from a particular domain using qmHandle. The spam emails are having different subject lines, but originating from one particular domain.

Please assist.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-29 at 06:54:15ID24770017
Tags

Qmail

,

qmHandle

Topics

Qmail Email Server

,

Web Servers

Participating Experts
1
Points
150
Comments
6

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Spam, Spam, Spam, Spam!
    No, not a call for a Monty Python reunion......... We are a small (40-50 mailboxes) company running a single Exchange 2000 server. Lately our spam has shot through the roof. I am just beginning to look for a blocking solution and would appreciate pointers about what has wo...
  2. Spam Assassin
    Okay i have two server, both running Spamassassin, with two different configure files. One server handles Spam GREAT! I mean it is really good. But it is running MailScanner with Spamassassin So i am not sure if MailScanner is stopping all the spam or if it is Spamassassin...
  3. Is this email a spam?
    I receive this email all of sudden, but not sure if it is a spam or even a phish. Can someone help me with it? email message: From: InterNic.ca Customer Service [service@internic.ca] Subject: Contact Information Update A support account has been created for you with the follo...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: it4sohoPosted on 2009-09-30 at 09:59:28ID: 25460866

There is an easier solution...

Standard QMail includes a file in /var/qmail/control called "badmailfrom"

Simply add the domains you want to block in that file and you're set... for example:

.*\ @.*
!.*@.*\..*
.*%.*
@spammer.com

The first line says you won't accept mail from domains with a SPACE in the domain name (clearly illegal)
The next line says you won't accept mail from domains with both a ! and @ in them (a common old-time hack)
The 3rd line says you won't accept mail from domains or users with a % in them (also illegal)
The LAST line says you won't accept mail from anyone at spammer.com (substitute your own spam-source domain)

NOTE: the first 3 should be in ALL QMail installs... the last has one problem... if they say the mail is from bob@mail.spammer.com, your rule won't match. Now, the first attempt to fix this might be to make the line say just:
spammer.com

But in that case, you'll also block an e-mail from bill@not-a-spammer.com... so here's the BEST way.... (using 2 lines!):
@spammer.com
.*@.*\.spammer.com
which says you block anything that ends in @spammer.com, then you ALSO block anything that is of the form "somebody@something.spammer.com" -- so long as the last part is .spammer.com. Thus, bill@not-a-spammer.com does NOT match (it doesn't match the first rule, and there is not a . in front of spammer.com, so it doesn't match the 2nd either)

Probably WTMI... but now you know how to block messages!

BTW: there is also a badmailto file -- so you can likewise block messages from EVER going to specific places.
The DEFAULT entries should look like:
[\(\)]
[\{\}]
@.*@
[\%]
[\!]


Line 1: No parens
Line 2: No braces
Line 3: No brackets
Line 4: No double-@'s
Line 5: No %
Line 6: No !

The latter two FORCE your users to use the more modern (and more globally accepted "name@domain" format, as opposed to the older (and depreciated) domain!user)... and QMail has special-uses for the otherwise illegal character of %

So, to disallow ANY messages going from your server to hotmail.com, just add
@hotmail.com

to the bottom of badmailto and voila --

I hope this helps... in spite of the WTMI!

Dan
IT4SOHO

WTMI = "Way Too Much Information"

 

by: testezPosted on 2009-10-01 at 03:01:10ID: 25467168

Hello it4soho,

Thanks for your reply. Consider the following situation, I can see the spam emails from that spamming domain in my qmail queue. Its stuck there. How to remove the spam emails of that spamming domain from queue which is having different subject lines.

Any ideas?

 

by: it4sohoPosted on 2009-10-02 at 07:41:43ID: 25478358

If the "SPAM" is in the queue, it is likely on its way OUT, not IN...

Let's understand the "basics" of a QMAIL queue....
A message comes into the QMail system for delivery:
 - The message is assigned a unique message ID (a number)
 - The message is entered into the QUEUE as follows:
   - The message itself is placed into a file named the MSGID in the "mess" folder
   - If there are local recipients, a file is created named the MSGID in the "local" folder. This file contains a LIST of all of the local recipients and whether or not the delivery to their mailbox has been completed
   - If there are remote recipients, a file is created named the MSGID in the "remote" folder. This file contains a LIST of all of the remote recipients and whether or not the delivery to their mailbox has been completed
 - Periodically, separate QMail processes look through the local and remote folders to see if messages need to be delivered
 - Periodically, another process checks the folders -- if a message ID no longer has any recipients awaiting delivery, then the files with the MSGID names are finally removed from all locations.

So -- take this information and build a script to do what you want... (There are LOTS of other scripts out there -- much more powerful, much more elegant -- and thus, safer to your queue -- but this will get done (by brute force) what you want.


==== Script.sh =====
#!/bin/bash
#
# STOP QMAIL BRIEFLY TO DO THIS! (Do this the RIGHT way for your system -- this is a RH example)
service qmail stop
#
# put the domain who is sending SPAM in the variable below
BADSENDER=baddomain.com
#
# Assumption: your queue folders are in /var/qmail/queue
ALLMSGS="`find /var/qmail/queue/mess/* -type f -print`"
for MSGID in $ALLMSGS ; do
  if grep -i "^from.*${BADSENDER}" /var/qmail/queue/mess/$MSGID > /dev/null 2>&1 ; then
    # Assumption: you are already using qmHandle
    qmHandle -d$MSGID
  fi
done
#
# Restart QMail processing
service qmail start

==== Script.sh =====

What you've done:
ALLMSGS contains all of the MSGIDs in the mess queue (remember, the message "body" is there, regardless of whether delivery is local or remote).
In the FOR loop, we look inside the message for a line that starts with from & contains the bad domain sender
For those files that are found, the qmHandle program is used to remove those entries from the queue "cleanly"

COMMENTS:
Yes, I could have done this in fewer steps -- in fact, I could have done it with a single FOR loop so that you could just enter it on the command line -- but it would be much harder to describe what I'm doing and would be of little value (unless your queue had tens of thousands of entries!)

I hope this helps!

Dan
IT4SOHO

 

by: testezPosted on 2009-10-05 at 03:36:49ID: 25493908

Hello IT4SOHO,

I have tried your script by replacing the baddomain.com with the domain spamming in our server. Also i have checked and confirmed that the queue folders are in /var/qmail/queue. But unfortunately the spam queue is still there and no mails were removed from the queue. The script just stops the restart the qmail. Any ideas?

 

by: it4sohoPosted on 2009-10-06 at 09:37:47ID: 25506968

You'll need to debug the script...

As noted within, I assumed that your qmail queue was at the "standard" location of /var/qmail/queue...

If your actual queue is located someplace else, then modifying that one entry could help...

I have tested the script as-shown on a system with the queue location I used and it runs correctly.... so I'm thinking that the queue location is the problem.

Let me know... if that's not it, try running the script in debug mode:
  bash -x /path/to/script

Capture that output & paste it in here and we'll see what we can find from there!

Dan
IT4SOHO

 

by: testezPosted on 2009-10-06 at 09:44:52ID: 25507056

Hi,

Thanks for pointing it.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...