0

I'm trying to solve a problem with a bulky program that is, for some reason, only sending email over port 25, even when port 587 is specified.

In this answer, someone suggests using the windows command netsh:

netsh interface portproxy add v4tov4 listenport=25 listenaddress=127.0.0.1 connectport=587 connectaddress=%uFEFF%uFEFF<ipaddress of the real email server>

Basically, it just changes the Windows IP rules such that anytime a connection over port 25 is made to 127.0.0.1, it forwards it to port 587 of the remote e-mail server.

I have seen some examples using iptables that come close, but I can't figure out the perfect one for forwarding to a remote e-mail server. Most iptable examples are only for forwarding within the local machine. If possible, I'd ike to use iptables with a domain name as well. Postfix is a bit annoying because it is a huge program when in reality, on a lot of servers, this ip rule will work a lot better for me

TL;DR If someone could help, I'd like to setup an ip rule to forward as follows:

Input domain: 127.0.0.1
Input port: 25
Output domain: smtp.gmail.com 
Output port: 587

This would also be useful for me for some other projects too.

Edit: Here are the commands that I have tried:

 sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 25 -j DNAT --to-destination 169.47.148.173:587 # The 169 ip is for smtp.sendgrid.net
iptables -t nat -A POSTROUTING -j MASQUERADE
iptables -F

I know the rules are active because i can list them with iptables nat command. iptables -t nat -nvL

But I still get a failure when trying to send the email through this stupid program, when specifying host 127.0.0.1 and port 25. I also specified a UDP forwarding rule too, still fails.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.