If you need more info have a look in the bookmarks section on iptables:
And try to concentrate on the syntax that you would use to feed those commands into iptables buy hand.
What you need to realize that your script will actually perform this command (depending on your setup the interfaces eth0/1 differ):
iptables -A FORWARD -i eth0 -o eth1 -p tcp -s 18.104.22.168 --dport 587 -j ACCEPT
First start by learning to execute these commands by hand, and then later write scripts to execute these same commands.