Restricting outgoing SMTP with Exim

I am trying to secure my droplet to prevent too many emails being sent out possibly my malicious scripts that get injected to the server. I know one option would be to monitor the logs and when a certain limit is exceeded per hour I get notified by email but I would like to know if there is a way to set limits to how many outgoing emails can be sent by the server or for a way to restrict outgoing smtp to only specific users i.e. exim, sendmail and root.

I have a droplet with Ubuntu 14 and Exim4.

Any help would be greatly appreciated. Thanks

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hey there,

As mentioned here, you can restrict how many emails per hour a user can send out with the following in your exim configuration:

ratelimit = 50 / 1h / strict / $authenticated_sender

Personally I’ve used csf to alert on such an occasion. You can set the emails sent to root to forward to an email account that you can keep an eye on. You can do this by placing a file with an email address named /root/.forward. Some systems may prefer a different method or settings (SELINUX contexts for example).

CSF controls the firewall by writing it’s own iptables rules. You can use the /etc/csf/csf.conf file to set the default allowed ports in and out for both TCP and UDP. There are other configuration files like /etc/csf/csf.allow and /etc/csf/csf.ignore / /etc/csf/csf.pignore where you can whitelist IP addresses and processes.

LFD is another component that is installed with CSF. It stands for Login Failure Daemon. That process will watch for failed login attempts and automatically block IP addresses. It will also watch mail logs and alert when there are excessive emails sent per hour or suspicious processes running.

Here is an article that describes the install and setup of CSF on Ubuntu.

While it’s a little more complex than rate limiting exim, it really helps pinpoint the issue and the exact cause. More often than not you’ll be notified of the exact script generating the emails.

Happy coding,

Jon Schwenn Platform Support Specialist DigitalOcean