I should begin by saying that Mail.app is a very pleasant mail reader to use. Sadly, it's just not powerful or practical when it comes to really interacting with real world network environments. In particular, it has none of the essential pre-connect or tunneling features of the unix mail readers like mutt. About the only thing one can control is the ports of the servers your using; luckily that is enough when you have root access to you own machine. Anyway, I got sick of needing to manually set up ssh port forwarding every time I wanted to send mail from my laptop when I was off campus, so I set up the following little trick to make it automatic.
[robg adds: I haven't tested this one...]
First, I use multiple mail accounts and I don't want my mail outgoing mail server to say localhost in the Mail.app, so I changed the 127.0.0.1 localhost line in /etc/hosts to read:
127.0.0.1 localhost joe_mail bob_mailYou can just ignore all the bob stuff to make it work smoothly with just one server, named joe. Second, we create two new service identifiers by adding the following four lines to /etc/services, though I think you should only need the /tcp lines:
joe_sm 1025/tcp joe_sm 1025/udp bob_sm 2025/tcp bob_sm 2025/udpThird, we create two new pseudo-daemon's by adding the following two lines (shown as two lines per entry; enter as one long line each) to /etc/inetd.conf:
joe_sm stream tcp nowait nyarlathotep /usr/libexec/tcpd /usr/bin/ssh -T -q joe.fuq.edu /usr/bin/nc localhost 25 bob_sm stream tcp nowait nyarlathotep /usr/libexec/tcpd /usr/bin/ssh -T -q bob.fuq.org /usr/bin/nc localhost 25This obviously requires that ssh be configured for automatic login, which I should not need to explain (see this hint), and you can obviously replace ssh with other passsword-free connection methods, like say an expect script. You should be careful of MOTDs and greetings, as these confuse Mail.app unless they are blocked. The /usr/libexec/tcpd wrapper is not strictly necessary, but it provides some security, see below.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20030827145105498