Emails Are Being Sent Without Permission – How to Block All Outgoing Mail and Allow Only Incoming?

SYSTEM INFORMATION
OS type and version Ubuntu Linux 22.04.5
Usermin version 2.302
Virtualmin version 7.30.8
Theme version 24.02
Apache version 2.4.52
Package updates 27 package updates are available

My server is being abused to send unauthorized spam emails from my email to Gmail and others. These messages are flagged or blocked, and I see many in the Postfix mail queue.

I want to completely block all outgoing emails, but still allow incoming mail to be received normally.

How can I configure this safely in Postfix/Virtualmin?

@sherif.abousamra95,

Most likely being sent from a script on your website, though you haven’t told us much about the issue to provide much assistance yet.

thanks for your feedback
the issue is there is emails being sent from my username to google and other accounts and i want assistance to stop it from happening

@sherif.abousamra95,

Do you run a PHP based site with a contact form?

It could be the case the server is compromised but either way i would be inclined to start from scratch creating all the domain(s) users with different strong passwords. There is the case that some bad code has been injected into the website files and will reinfect from a backup. @sherif.abousamra95 depending on how the mail is being sent looking at the logs will help to ascertain how mail is being sent, if it is being sent via a remote user that has your password (using submission) change the users password, but if you really want turn off sending mail why not try removing all submission configuration from postfix master.cf which i guess will stop mail being sent

i have roundcube

i will still be able to receive emails?

I hope you cleared the queue else these will continued to be sent.

You have at least one ‘bad’ local email address.

You need to check the logs and see where these are coming from. Also check the FULL headers. It could be ‘back scatter’ and you are getting emails bounced back that didn’t originate with you. Does michelle@cp… have a web site? They could have a bad web form or compromised site. Or maybe michelle@cp… is actually a spammer or has a compromised mail account.

Personally I’d grep the mail logs for one of the codes and find all information about it. You probably need to change lines to 10000 or so and use the filter to find all instances of someting like the 021cb3…

Figure out which user is sending spam, then take appropriate action.

If the user is a domain owner user, and the sender is an exploited web application, you need to fix that exploited web application.

You can certainly configure Postfix to be more strict about who can send under what circumstances (e.g. require authentication, or only some users can submit to the local queue). But if you have an exploited web application, which seems likely, spam is a symptom, not the disease, and you need to treat the disease. An exploited web application is dangerous in all manner of ways, spam being among the least destructive. Be grateful the attacker just wanted to send spam and not do something much worse (but they may be doing something much worse, as well, you won’t know as long as you treat the symptom and not the disease).

https://serverfault.com/questions/234026/how-to-disable-local-relay-in-postfix-for-unauthenticated-users

1 Like

is there a way to use it to receive emails only (IMAP)?

yes you will still get emails

I need to keep port 25 open to receive emails, but when I do, it gets attacked. If I block it, the attacks stop — but so does email delivery. So I’m stuck between allowing attacks or losing incoming mail

I thought this thread was about stopping emails being sent but it appears you are worried about attempted logins via port 25.If that is the case make sure you have all the postfix fail2ban jails enabled with whatever defaults you want which will then start banning users that are attacking.


attacks like these are simply banned

You didn’t read my comment, I guess. I’m not inclined to help if you’re not inclined to take the help offered.

A firewall is not the solution to this problem.

I’m new to all this and using ChatGPT to help me understand, so it’s a learning curve. I did try your method and I think it’s working now, but I’m not totally sure yet. Appreciate your help!

We’re always happy to answer questions (but ignoring advice and asking the same question multiple times is discouraged).

If it’s not obvious from the items in the queue which user is sending email, you can generally find out in the relevant log (the postfix unit in the journal on modern systems). We have docs for troubleshooting mail problems, which includes how to find the relevant mail logs and how to browse/search them, etc.

Thanks, I’m not ignoring — as I mentioned, I’m still learning and trying things I somewhat understand first. I’ll check the docs you shared.

Also, to avoid confusion, is there a way to configure the server to only receive emails but not send? I tried blocking port 25, but then I couldn’t receive anything either.

Thanks again!

I gave instruction on how to do this very early on in the thread but let’s try again
get to this point


and you will see this change the file to master.cf as shown by the arrow

near the bottom of the file you will see lines like this

change them so they look like this by putting a # at the begining of the lines

then save & close the file

click the arrowed button

1 Like