I have two ISPs at two separate locations, both with separate SMTP servers. Neither SMTP server allows relaying from the other ISP, so when taking my laptop between each location, I have to swap between smtp servers.
I currently edit the /etc/hosts file to override smtp.magichost.com with the IP addresses of the SMTP server I'm supposed to be using, but that is a pain.
Is there a better way to do this?
If you are using Thunderbird, you can try installing the SmtpSelect extension.
If you are trying to solve the more general problem, most (at least the ones I work with) ISPs allow you to authenticate and submit mail to the mail submission port (587). Perhaps this will work for you.
If that still doesn't work, sign up for a gmail account and use gmail's mail submission port (smtp.gmail.com:587) to send your mail out.
If you really don't want to do that, setup some sort of smart script that wakes up every n minutes, checks to see where it is, and reconfigures /etc/hosts or /etc/mail/mailertable to redirect the mail appropriately.
Mail Switch is an application that claims to be able to do this for you, selecting the mailserver based on the network you are connected to.
Another solution may be to just use one of the ISP's mail servers, but with authentication enabled.
Allowing un-authed access from your own network (as an ISP) is fine, allowing external access would just mean anyone could use you as an Open mail relay. However your ISP may allow you to authenticate your outbound mail connection and this way allow you to send from a location where you aren't connect to their network.
as an example, my ISP has mail.internode.on.net as their regular server and securemail.internode.on.net as their authenticated server, this means I can send and receive my emails via an encrypted connection, wherever I am in the world.
It would help greatly to know what application you're using to send mail.
If you're using Outlook, just set up two separate POP3 accounts in one profile. Each one should have the different SMTP host. Make one of them with an invalid incoming mail server (such as test), remove that account from the Send/Receive group (Tools > Options > Mail Setup > Send/Receive), and then when you're sending mail, an "Accounts" button appears on the toolbar to switch between which account is sending the mail.
Probably want to use a comprehensive network profile switcher tool like MobileNetSwitch (see page 24); it allows dynamically adjusting SMTP, Outlook, hosts settings when you select a network profile. On top of all the other crucial setting switches which I swear by when using a laptop across various sites.
In the past, I have used the cygwin version of the Exim mail server, configured as a Windows service on my laptop. Then I just set my mail client to use 127.0.0.1 as the outgoing SMTP server, and the laptop delivers its own mail!