How to remove all messages from exim mail queue from a certain user/email

708

Solution 1

Delete all messages that are from [email protected]. You can add -v to the exim command in order to get more verbose output.

exiqgrep -i -f [email protected] | exim -Mrm

You can do it a slightly different way where you generate a bounce message for each item. This emphasizes to the end user how much harm their compromised mailbox has been causing:

exiqgrep -i -f [email protected] | exim -Mg

Solution 2

Use this line to delete all messages:

exim -bp | grep [email protected] | sed -r 's/(.{10})(.{16}).*/\2/' | xargs exim -Mrm

It does the following:

exim -bp

Lists the exim mail queue

grep [email protected]

Selects only the lines with a certain mail address

sed -r 's/(.{10})(.{16}).*/\2/'

Selects the ID of the e-mail

xargs exim -Mrm

Deletes the message from the queue

I'm sure it can be optimized, please tell if so and how!

Solution 3

The other way to clear exim queue is by print the third fields which in this case will be the email email address. Any result that matches the grep email address will be deleted by exim -Mrm command.

exim -bp | grep [email protected] | awk {'print $3'} | xargs exim -Mrm

In case if you would like to clear the frozen email, you can replace [email protected] with 'frozen'

Share:
708

Related videos on Youtube

Miguel Ortiz
Author by

Miguel Ortiz

Updated on September 18, 2022

Comments

  • Miguel Ortiz
    Miguel Ortiz almost 2 years

    I've been working with Flask for quite a bit.

    I have an output, just a number which increases or decreases constantly, I want to capture it with flask POST method and, retrieve immediately.

    I've created an application to retrieve the latest POST in a GET method using the same context:

    cumulative = ['x']
    @app.route('/xxx', methods=['GET', 'POST'])
    def refresh():
        aexample = request.get_json()
        cumulative.append(aexample)
        return str(cumulative[1]['thing2'])
    

    It works, but if you refresh the page sometimes this error appears in the logs:

    TypeError: 'NoneType' object is not subscriptable
    

    In this line:

    cumulative.append(aexample)
    

    I've tried using:

    cumulative[0] = aexample
    

    But that doesn't work, it says the value is "None". That's why I made it incremental (just for test purposes).

    All of this makes me think, storing the latest POST values in a list isn't the smart way to do this.

    I've been thinking on using some sort of cache, the posted value changes every minute and I would like to retrieve only the latest posted value. I'm not interested in storing the values permanently.

    Is there a good way to do this?

    • roganjosh
      roganjosh almost 5 years
      Store the values for who? How many people use the app?
  • vstm
    vstm over 9 years
    Instead of sed ... I normaly use awk '{print $3}' - prints the third column with the IDs. It's a tiny bit shorter.
  • liamvictor
    liamvictor almost 9 years
    Alternatively, you can use exiqgrep to get the same effect without the sed or awk.
  • Saxtus
    Saxtus over 5 years
    Does that work without xargs after the pipe?
  • Miguel Ortiz
    Miguel Ortiz almost 5 years
    @roganjosh the route /xxx should display the latest POST value for anyone who access it with a GET method.
  • Miguel Ortiz
    Miguel Ortiz almost 5 years
    Thanks, yes, you were right, to solve the error I've added conditionals per request type!
  • ygoe
    ygoe about 4 years
    This doesn't work: "exim: no message ids given after -Mrm option"
  • ThomasEdwin
    ThomasEdwin about 4 years
    These work for me: exiqgrep -i -f [email protected] | xargs exim -Mrm and exiqgrep -i -f [email protected] | xargs exim -Mg