Or, how to use Fetchmail to reliably move large quantities of email from one place to another
If, like me, your normal email machine has vanished into a black hole at some service department somewhere *cough*apple*cough*, then you’ll quite quickly find out that :
- Being un-connected is a strange, but not wholly unpleasant experience..
- .. but you still need to get at your email, but you don’t want to be setting it up on another machine because then you’ll just have email spread in a whole bunch of different directions
Fear not - the solution to the problem is just to create a webmail account with GMail* and use Fetchmail to push all of your email in there. All you need is a little terminal magic, and a program which is installed by default in OS X.
You will need to gather up the following information :
- Your current mail server details - host, username, password.
- You’ll also need to know the email address you’re going to be squirting it all into
- as well as the mail server which will be accepting all of this mail for you. This is possibly the more complicated part, and I’ll explain how thats done
For the webmail, I’ve started re-using a gmail account, which I was previously using before I switched over to mac mail. I already know the email address for that - but I need to find out the email server which I can sent email into. I can do that using a bit of prodding around in the plumbing of the internet. I’ll take the domain name I’m sending to (@gmail.com in this case), and I’ll query the DNS system to tell me where email to that domain should be sent.
nslookup -q=MX gmail.com. I’ll get a response back, something like :
gmail.com mail exchanger = 5 gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 10 alt2.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 50 gsmtp163.google.com.
gmail.com mail exchanger = 50 gsmtp183.google.com.
The important bit here is the one with the lowest number - in this case it’s gmail-smtp-in.l.google.com - we’ll make a note of that, and move on.
Open up your terminal, and type the following command
nano -w .fetchmailrc
This will bring up the nano text editor and a blank document. We’re going to be creating a configuration file for fetchmail, so it knows where it’s getting the mail from, and where it’s sending it to. The following is a sample configuration. Replace the … parts with the actual hostnames, usernames and passwords :
poll ...your-current-mailserver... protocol pop3
username ...your-current-username... password ...your-current-password...
smtphost ...the-smtp-server retrieved above...
smtpname ...your temporary email address...
So, you should end up with something like
poll mail.mymailservice.com protocol pop3
username myusername password mypassword
smtphost gmail-smtp-in.l.google.com
smtpname newuser@gmail.com
Now, you are ready to test it out - save your configuration using CTRL+O and then CTRL+X to exit nano. Change the permission on the file
chmod 710 .fetchmailrc
and then run fetchmail
fetchmail -v
Fetchmail will now run, hopefully it’ll start printing lots of stuff across the screen, showing it’s managed to retrieve messages and pushing them on, into your new account. Congratulations, you should start seeing your email turning up in your temporary account shortly
It’s possible to set fetchmail to run in the background, using the -d option, although it won’t automatically run once your mac has rebooted. If this is a short-term measure, or a one-off, then continue to run it manually. You can search around for getting fetchmail running in daemon mode
* Gmail - yes, I know you can configure gmail to download POP email straight into GMail, but in my experience that is a little less than perfect, and if you have a lot of email waiting, it won’t transfer the whole lot in a single go. In addition, you can set gmail to send out using your real email address, rather than your new gmail address - and you can then download your email back out of Gmail again via POP3 once your machine is up and running
If you are going to be taking mail from your Mac Mail, and importing it into GMail, then Salted-Wound has some advice






Post a Comment