How Can We Help?

Postfix Commands

You are here:
< All Topics

start and stop postfix

 

 

systemctl start|stop|restart|enable postfix
systemctl status postfix

 

root@gemini:~# systemctl restart postfix
root@gemini:~# systemctl status postfix
● postfix.service – Postfix Mail Transport Agent
Loaded: loaded (/lib/systemd/system/postfix.service; enabled; vendor preset: enabled)
Active: active (exited) since Wed 2022-03-09 12:25:54 UTC; 5s ago
Process: 159667 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 159667 (code=exited, status=0/SUCCESS)

Mar 09 12:25:54 gemini systemd[1]: Starting Postfix Mail Transport Agent…
Mar 09 12:25:54 gemini systemd[1]: Finished Postfix Mail Transport Agent.
root@gemini:~#

 

 

Display postfix logfile

 

tail -f /var/log/mail.log

 

 

Send a test email from command line

echo “Test email body” | mail -s “Test Subject” -a “From: you@yourdomain” recipient@example.com

echo “Test email body from gemini” | mail -s “fri 11 march 11PM: Testing from gemini using SMTP” -a “From: kevin@kevwells.com” kevwells@gmail.com

 

 

List mails in the queue with postfix

 

mailq

 

root@gemini:/etc/postfix# mailq
-Queue ID- –Size– —-Arrival Time—- -Sender/Recipient——-
20D4B9285 15688 Mon Mar 14 14:02:25 www-data@kevwells.com
(connect to smtp.gmail.com[2a00:1450:400c:c07::6d]:25: Network is unreachable)
kevrwells@gmail.com

8F2A39277 5376 Mon Mar 14 10:04:18 kevinrwells@yahoo.com
(connect to smtp.gmail.com[64.233.184.108]:25: Connection timed out)
kevrwells@gmail.com

— 20 Kbytes in 2 Requests.
root@gemini:/etc/postfix# cd
root@gemini:~# mailq
-Queue ID- –Size– —-Arrival Time—- -Sender/Recipient——-
20D4B9285 15688 Mon Mar 14 14:02:25 www-data@kevwells.com
(connect to smtp.gmail.com[2a00:1450:400c:c07::6d]:25: Network is unreachable)
kevrwells@gmail.com

8F2A39277 5376 Mon Mar 14 10:04:18 kevinrwells@yahoo.com
(connect to smtp.gmail.com[64.233.184.108]:25: Connection timed out)
kevrwells@gmail.com

— 20 Kbytes in 2 Requests.
root@gemini:~#

 

 

Delete all emails in the postfix queue

 

postsuper -d ALL

 

root@gemini:~# postsuper -d ALL
postsuper: Deleted: 2 messages
root@gemini:~#

 

Remove all mails in the deferred queue

 

postsuper -d ALL deferred

 

 

Remove a particular mail from the queue

 

postsuper -d mail_id

 

 

 

Remove messages from a particular domain

 

Obtain the mail queue ID on running the mailq command

 

mailq | grep domain.com | awk {‘print $1’} | xargs -I{} postsuper -d {}

 

To list the postqueue

 

root@gemini:~# postqueue -p
Mail queue is empty
root@gemini:~#

 

 

Check your hostname

 

root@gemini:/etc/postfix# hostname -f
gemini
root@gemini:/etc/postfix#

 

 

Locate the postfix configuration directory with postconf

 

root@gemini:~# postconf | grep config_directory
config_directory = /etc/postfix
root@gemini:~#

 

 

Update the postfix lookup table

 

root@gemini:~# postmap /etc/postfix/virtual
root@gemini:~#

 

then reload the postfix configuration:

systemctl restart postfix

 

 

Run postmap to create the file sasl_passwd as a Berkeley DB file

 

root@gemini:/var/mail# postmap /etc/postfix/sasl_passwd
root@gemini:/var/mail#

 

Check postfix active listening ports

 

ss -lnpt | grep master

 

root@gemini:/etc/apache2/sites-enabled#
root@gemini:/etc/apache2/sites-enabled# ss -lnpt | grep master
LISTEN 0 100 0.0.0.0:25 0.0.0.0:* users:((“master”,pid=173714,fd=13))
LISTEN 0 100 0.0.0.0:587 0.0.0.0:* users:((“master”,pid=173714,fd=18))
LISTEN 0 100 [::]:25 [::]:* users:((“master”,pid=173714,fd=14))
LISTEN 0 100 [::]:587 [::]:* users:((“master”,pid=173714,fd=19))
root@gemini:/etc/apache2/sites-enabled#

 

 

Table of Contents