Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Automatically retrieve received emails into Mail Apps
There's a nice way to get at your email instantly, so that less than a second after the mail is sent, it shows up in Mail.app. It's a bit complicated, though. If you can't get it to work, don't worry: someone will probably write a $10 shareware thingie to do this automatically. First, we need to make a script for checking mail. Put the following in ~/bin/check-mail:
#!/bin/sh
osascript -e 'tell application "Mail" to check for new mail'
Then do chmod 755 ~/bin/check-mail, and make sure the script works before you proceed. Next we'll need to open a port. We're lazy, so we'll just use the gopher port. Create the file /etc/xinetd.d/gopher with this in it:
service gopher 
{
  port = 70
  socket_type = stream
  wait = no
  user = your_username
  server = /Users/your_username/bin/checkmail
}
Note that the {}'s have to be on separate lines. Then type sudo service gopher start. To see if this works, type telnet 127.0.0.1 70. The Mail application should go fetch your mail. Now for the juicy part: add this to your .procmailrc file (on the mail server):
:0c
| wget -T 5 -q http://your-home-ip:70/
With this in place, whenever you receive mail, Mail.app will immediately go fetch it. No need to keep hammering the server every five minutes. If you keep moving your computer around, you might find it helpful to get a hostname from dyndns.org.

[robg adds: I haven't tested this one...]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[7,328 views]  

Automatically retrieve received emails into Mail | 11 comments | Create New Account
Click here to return to the 'Automatically retrieve received emails into Mail' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automatically retrieve received emails into Mail
Authored by: nathanst on Nov 28, '03 12:01:27PM

Just thought I'd explain what this is doing, since the hint doesn't.

Gopher is a service that existed prior to the web that offered similar services, but without the ability to customize the interface with html. This hint sets up a gopher server on port 70 of your machine.

BUT, instead of offering gopher services, the "server" that is executed to handle the request is actually the script that tells mail to check immediately.

Finally, on your mail server, a .procmailrc file allows the computer to execute special instructions each time you receive mail. In this case, the server is being told to try to contact your gopher server each time new mail comes in.

So, this is the process:

* Mail arrives in your account.
* Procmail contacts port 70 on your machine.
* Your machine receives the request.
* The applescript runs that tells Mail to check immediately.

Typing "telnet 127.0.0.1 70" also tests this, because it does the same job of contacting port 70 on your machine.

Know that malicious people around the web are continually scanning IP addresses and trying different exploits on open ports, so it is possible that you will find yourself checking e-mail each time you get hit with one of these port scans.

Also know that if you make a mistake in your .procmailrc file your mail could just vanish, so be careful to type stuff in correctly, and test it immediately.

Writing a $10 program to do this automagically? If someone does it, it better be free. (pretty simple to do)



[ Reply to This | # ]
Automatically retrieve received emails into Mail
Authored by: mkhaw on Nov 28, '03 12:39:58PM
A couple of questions:
  1. After a reboot is it necessary to re-execute sudo service gopher start?
  2. Does it have to be a tcp stream connection? Would a udp connection work? If so, it should be possible to use the more apt comsat/biff port instead.


[ Reply to This | # ]
Automatically retrieve received emails into Mail
Authored by: GoobleyGook on Nov 28, '03 06:25:02PM

A question: What do you mean "Put the following in~/bin/check-mail"? There is no "bin" directory in any "Users" folder. Do you mean create "~/bin/check-mail"?



[ Reply to This | # ]
Automatically retrieve received emails into Mail
Authored by: nathanst on Nov 29, '03 12:55:04PM
After a reboot is it necessary to re-execute sudo service gopher start?
    It shouldn't be, because you are placing the file where all services go, and OS X automatically starts them. But, I haven't tested this.
Does it have to be a tcp stream connection? Would a udp connection work? If so, it should be possible to use the more apt comsat/biff port instead.
    You can really should be able to use any port or service. For instance, you could create a special web page that does the same thing, and then you wouldn't have to start any other services at all.
A question: What do you mean "Put the following in~/bin/check-mail"? There is no "bin" directory in any "Users" folder. Do you mean create "~/bin/check-mail"?
    Not my hint...but yes, that's what the author means. You should probably keep this in your User folder, but you can really put it anywhere out of the way.


[ Reply to This | # ]
Automatically retrieve received emails into Mail
Authored by: ultimanine on Nov 28, '03 03:48:07PM

I'm partially confused about the "(on the mail server)" aside. What exactly does he mean by that? I'm probably missing something blatantly obvious here.

---
Macs and music:
saviors of society



[ Reply to This | # ]
Automatically retrieve received emails into Mail
Authored by: mweissen on Nov 29, '03 10:17:41AM

It means that you should (1) log onto the mail server or any Unix host with access to the mailbox, (2) configure it to pass all your incoming mail to the procmail program, then (3) configure procmail to signal your Mac over the network whenever an email comes in, then finally (4) configure your Mac to fetch all email whenever it gets this signal.

Very elegant, but difficult to set up, and if you make a mistake in the .forward or .procmailrc configuration files you can lose your incoming mail all too easily. Besides, it only works on mail servers where you have shell access (e.g. you can log in using SSH). As far as I know, Mac.com will *not* work.

Search Google for the keywords procmail tutorial, there are lots of web pages which tell how to set up procmail on a remote host.

--Martin



[ Reply to This | # ]
Stupid Hint - Automatically retrieve received emails into Mail
Authored by: seunghun on Nov 30, '03 03:05:39AM

While I applaud ingenuity of this hint, it's of no use to crapload of people.

I mean how many people have a mail server that you can log into?

People have webmails nowadays. It's lucky to have a POP or IMAP account anywhere.

If you have corporate account, chances are, your mail is running on exchange.

Let's say your mail server runs unix. And let's just say you have a shell account at there. and that's a huge if. What is the chance that your site runs procmail? I know I don't. It's buggy and insecure. I ain't trusting my users with it.

Even if your mail server is running procmail. In fact. let's assume that you are a university student or something of the sort. Hell, then you might as well run mutt on the damn mail server. You have a shell access to it, anyhow.

Mostly, what this hint pisses me off the most is that it was only into the middle of the hint that i understood what was going on - and what the requirements are. Most of the people reading this hint haven't much idea about procmail or xinetd. The author should have told upfront what this hint requires - a dream configuration.

Christ, you might as well as run your own damn mail server. (Which is more trouble than it's worth, trust me. Not on residential IP you better not try to; AOL and the big players will deny mails from your mail server.)



[ Reply to This | # ]
Stupid Hint - Automatically retrieve received emails into Mail
Authored by: cynikal on Nov 30, '03 02:48:36PM

While you have a valid point that most people don't have login access to their email server and that a lot of people have webmail nowadays, i'd have to disagree that most people use exchange server. There's quite a few people that do, but i think the majority of mail servers are still on Unix. Like you, i have no hard numbers to back this up either way.

As for procmail, i don't know why you claim it's insecure. Maybe you're thinking of sendmail? Now that's a security nightmare. Any one program that has so many tasks isn't a good idea from a security standpoint.

And actually I do run my own mail server and it's not all that much of a nightmare :-P it's actually quite straightforward, try postfix, you can have a mail server up in less than 10 minutes (including compilation time).

Why would you want to log onto the server to run mutt/pine/elm, that's way unintuitive in the point-and-click realm. Then again, I still run elm when i need to do something with attachments on the mail server end.

But in any event, the author definately should have mentioned the requirements at the beginning:

1.) a mail server you can log into running unix
2.) procmail on that server
3.) a publicly reachable ip address on the mac running mail (if you're behind a firewall, you won't normally be able to have the script triggered)

these three things aren't that hard to find, and in most cases a work around can be found (like port forwarding on the firewall).



[ Reply to This | # ]
Stupid Hint - Automatically retrieve received emails into Mail
Authored by: seunghun on Nov 30, '03 06:54:08PM

i used to use qmail and read all of my mails on mutt. (using fetchmail for a while as well as my own account on the server) I still read my mails on mutt. No procmail was involved; I am actually a fan of Maildir.

My point about having own mail server is that AOL and a few other ISP have started blocking mails from residential IP as an anti-spam measure. Go ahead and try to send an email to your AOL friend. It'll get bounced because you are on a residential email. In my case, I needed to send a bunch of emails to a group of people, which a large percentage of used AOL. It just became too much hassle.



[ Reply to This | # ]
Stupid Hint - Automatically retrieve received emails into Mail
Authored by: rotaiv on Dec 01, '03 07:36:49AM

I run my own mail server (with sendmail and procmail) on a residential IP and personally, I don't think I'd every want to use an ISP's mail server again! The point about outgoing mail from residential IP is valid but that is not to say you even have to use your mail server for outgoing email.

What I do is configure my clients to use my ISP's official SMTP server for *outgoing* and use my own mail server (via dyndns.org) for *incoming* mail. This has worked great for me and while I have had some minor issues, it has been a lot less than my previous ISP.



[ Reply to This | # ]
A more secure way
Authored by: John Kiniston on Dec 01, '03 04:29:35PM

A better way to do this would be with SSH.

Instead of enabling your faux Gopher server and allowing anyone to pop your mail for you use ssh to run your command securely.

Change the
| wget -T 5 -q http://your-home-ip:70/

line to

| ssh -i mail.key your_username@your-home-ip /Users/your_username/bin/checkmail

Enable Remote Login on your Macintosh.

Create a special SSH key you will only use for this application with no password with:

ssh-keygen -f mail.key -t dsa

upload the mail.key file to your server

Edit or create a ~/.ssh/authorized_keys file on your local machine

Insert the contents of the mail.key.pub file as the first line of the file after the following text

no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="~/bin/checkmail"

The file should then look like this:

no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="~/bin/checkmail" sh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAxfz84hkjhasjfgu+M4mcnCysP6G5Ihe6YCmT9URgwgbdjiU1ijY1O7zsQPvx0Q9802D4k5NuIRQjyrZBMSOPJMkAS3JK3oaU6ZdtwFOJbah8iVwFWT/OKivAz6gGFkhEZt85WmqTxQAmJepHJLKJHq9QfuLssbd1i0ZHx6r/80c6OvfM/01LXU= your_username@JMacintosh.local


Please note the above text may wrap in places where it should be a single line.



[ Reply to This | # ]