Easiest way to block all outgoing mail to a domain

webmasteryoda

Well-Known Member
Apr 3, 2013
98
7
58
Serbia
cPanel Access Level
Root Administrator
Hello

I want to temporarily block all of the outgoing mails to yahoo.com

The reason is: Yahoo blocked my IP and they will unblock me if I stop sending mails to their server for at least 48 hours. Check this topic.

But, I cant expect my email users to obey... :) So, it could be much easier if I temporarily block them all for sending emails to Yahoo.

Any clues how to do it?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463
Hello :)

This post is a little older, but it's similar to what you are seeking:

Block Email to AOL

However, note that the /etc/cpanel_exim_system_filter should be used instead of the file mentioned in that post.

Thank you.
 

webmasteryoda

Well-Known Member
Apr 3, 2013
98
7
58
Serbia
cPanel Access Level
Root Administrator
Nope. It doesnt work. File exists and I can easily change it, but after any kind of change server stops sending mails completely.

Later, if I delete the lines or comment them, mail server works again.

I even tried to copy-paste these lines just to be sure I am typing correctly, but it doesnt work:

Code:
if $header_from: contains "@thedomain_you_want_to_block_to_aol"
then 
if $header_to: contains "@aol.com"
then
fail text "The message you want to send to the originator of this email"
seen finish
end
end

if not first_delivery
then
finish
endif
Is it matters where in the file I type my lines? At the bottom or somewhere in the middle?
:confused:
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463
It's possible those rules are no longer sufficient. Have you considered attempting to block the Yahoo mail IP addresses through your firewall instead? I found the following example in the search results on Google:

Code:
iptables -I OUTPUT -s 127.0.0.1 -m string --string "domain" -j DROP
Thank you.
 

webmasteryoda

Well-Known Member
Apr 3, 2013
98
7
58
Serbia
cPanel Access Level
Root Administrator
Thanks Michael.
I know that iptables is Linux firewall.
But my knowledge with command line is very poor.

So, you are suggesting me to type:
Code:
iptables -I OUTPUT -s 127.0.0.1 -m string --string "yahoo.com" -j DROP
via SSH?

If I do that now, how can I remove this block in iptables when I solve the problem?

Thanks in advance and please sorry for my limited knowledge.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463
Yes, you could try that command. However, it was simply provided as an example found in search results. It's not guaranteed to work, and you should use it as your own risk. To delete a rule, you could first search for the rule via:

Code:
iptables -L --numeric --line-numbers |grep yahoo.com
To delete it, simply run this command:

Code:
iptables -D INPUT 123
Replace "123" with the line number from the first result.

Thank you.
 

webmasteryoda

Well-Known Member
Apr 3, 2013
98
7
58
Serbia
cPanel Access Level
Root Administrator
Ok. Problem solved.

I dont know why, but previous method didnt work. Probably some changes in the cpanel exim filter syntax.

This is now correct and works nice.

Code:
if $header_to: contains "@yahoo.com"
then
fail text "Your message to inform email users about the problem..."
seen finish
endif
if not first_delivery
then
finish
endif
And now my email server blocks all outgoing mails to Yahoo. I hope that they will automaticaly remove me from the blacklist.

Cheers to all. And specially to cPanel crew.