> For the complete documentation index, see [llms.txt](https://sys.disetti.it/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sys.disetti.it/system-administration/postfix.md).

# Postfix

## Delete spam mail

### Delete mail which sender is <XXX@XXX.COM>

```
mailq | tail -n +2 | head -n -2 | grep -v '^ (' | awk 'BEGIN { RS = "" } { if (($7 == "XXX@XXX.COM")) print $1 }' | tr -d '!' | postsuper -d -  
```

### Delete bounce mail from the previous command

```
mailq | tail -n +2 | head -n -2 | grep -v '^ (' | awk 'BEGIN { RS = "" } { if (($8 ~ "XXX@XXX.COM")) print $1 }' | tr -d '!' | postsuper -d -
```

## Analysis with postfix-perl-scripts

### Extract information since today

```
pflogsumm -D today /var/log/maillog
```

### Extract all invalid recipient from log

```
pflogsumm -D today /var/log/maillog | grep -i "Invalid Recipient" | awk '{ print $4  }' | tr -d '<' | tr -d '>' 
```

### Extract all “User quota exceeded” messages from log:

```
pflogsumm -D today /var/log/maillog | grep "User quota exceeded" | awk '{ print $2 }' | tr -d '>' | tr -d '<'
```
