I get by with a little help from my friends / I get high with a little help from my friends
The Beatles
Email is tricky. After a week of delving into procmail, fetchmail, getmail, ssmtp, headers, formail, and other friends; I have finally solved my problem, the solution for which seems trivial, in hindsight.
The problem I set out to solve was how to get my IMAP mail from one email account (which does not support POP or server-side forwarding!) into my gmail account.
I settled on fetchmail, which I have used in the past, but only to get local mail delivery. Here’s how it can be used to forward mail to external accounts:
% cat ~/.fetchmailrc
set logfile "/var/log/fetchmail"
poll mail.example.org with proto IMAP
user 'noah' there with password 'pw' is 'noah' here
options keep stripcr ssl
mda '/usr/sbin/ssmtp -C/etc/ssmtp/example.conf me@myhost.com'
fetchmail has smtpname and smtphost commands (see the manpage) but I couldn’t get them to work with gmail. Instead I just use ssmtp as my mda. By specifying the config with the -C flag, I can send mail via multiple smtp servers.
% cat /etc/ssmtp/example.conf root=me@example.org mailhub=mail.example.org rewriteDomain=example.org hostname=example.org FromLineOverride=YES UseTLS=YES UseSTARTTLS=YES AuthUser=noah AuthPass=pw
That’s it. I tried a lot of different configurations before landing on this one, and this was the only config that correctly munges the “Reply-To:” and envelope headers (without resorting to procmail).