SMTP Crash Course

First, you need to retrieve messages from your pop server. Try the following:

telnet pop.comcast.net 110 (or whatever your pop server is)
+OK (rwcrpxc53) Maillennium POP3/PROXY server #159
user mycomcastuserid
+OK
pass mycomcastpassword
+OK Mailbox open, 4 messages
list
1 2425
2 3308
3 3434
4 1982
.
top 1 0
[headers for message 1…]
top 2 0
[headers for message 2…]
top 3 0
[headers for message 3…]
top 4 0
[headers for message 4…]
quit
+OK

TOP 2 0 means “get me the headers from message 2 plus the first 0 lines of the body”. If you want more details, see RFC 1939. Other interesting commands might be RETR (retrieve) and DELE (delete). Probably the best way to implement this is to write a POP proxy, so that Eudora connects to your proxy, and your proxy connects to your POP server. This way, you’ll be triggered whenever Eudora wants to retrieve email and/or you could trigger a connection to the real POP server yourself. Your proxy will see every message, and Eudora will see every message, with no conflict.

When the proxy sees a message, it can play around with it to figure out if it is worth sending an alert to you phone. If it determines it is, then it could connect to your smtp server (or, better yet, the smtp server for your phone company) and construct and send a message to you.

Off the top of my head, languages most appropriate for doing this would be Java, Python or Perl. C/C++/C#(?) (I don’t have much experience with C# so I can’t say for sure) would be down the list, because socket handling isn’t simple. I’d pick Java or Python ahead of Perl, because of simpler multithreaded programming (and this program would be cleaner multi-threaded). But programming languages are like hammers, they are simply tools that let you get the job done. You can use a sledgehammer to put in a picture hook, and an 5 ounce tack hammer to knock down a wall, but obviously one is better suited than the other for a particular task.

J2SE is “Java 2 Standard Edition”. What does this all mean? Java 2 means “java 1.2 or newer”, so Java 1.4 is Java 2. “Standard Edition” means “it’s not EE, i.e. Enterprise Edition, so it doesn’t come with an Application Server”.

What does this all really mean? Silly marketing dweebs have infested Sun.

Just download J2SE 1.4 SDK and be happy.

You’ll probably also want to download The Java Tutorial. Just get tutorial.zip, as it contains everything.

This is what I figured. I used to be able to relay, way back in 1996, but even then the message would be flagged “Apparently from:” rather than “From” or perhaps it was “From: username@soandso.com <unverified>”

I do have an account with abac.com, but I am accessing it from the outside. I can access my POP3 accounts (of course) with USER and PASS commands, but I don’t know of how to authenticate in STMP, or if it will even let me. The suggestion of USERID doesn’t help me.

I guess this is trivial, as I could get through with my Comcast, but the abac account has much less traffic, and if I want to communicate with my computer via cell, a forty-five minute lag is huge.

In a pigs eye! I’m quite familiar with both languages, having written multi-hundred thousand line programs in each of them. Although Java has its quirks, it is a pretty “clean” language. Well thought out, not too many warts or dark corners. C was similarly “clean”. C++ is a pigsty. They tried to be everything to everybody, and ended up with a mess. Just one silly example is the lack of garbage collection and requirement to cast objects to the proper type before they are deleted (and is that delete, or delete?). I won’t even mention the lousy I/O or STL.

I won’t drop names, but he’s one of K&R (you guess which), visited my employer in the early '90s. He sat down with all the geeks (including me), and somebody asked “what about C++?”. His answer was simply “don’t use it, too complicated”. Never got to ask him about Java, since it wasn’t around back then…

Here’s how SMTP authentication works (RFC 2554) and here is examples of AUTH in use. The examples don’t show MD5 (one-way hash) authentication, but the RFC does show it.

I just tried EHLO at abac.com, and it doesn’t give me back any AUTH mechanisms, so I would have to say no, abac.com doesn’t support SMTP AUTH.

Why not just communicate directly with the cell phone company’s mail server? They’ll accept the message, because it isn’t relaying when the destination is handled by that server. For example, my Cingular phone gets messages through [10 digit phone number]@mobile.mycingular.com. Here’s how to lookup the mail server(s) for this service:

nslookup
Default Server: ns.yourisp.com
Address: 123.24.34.2

> set qt=mx
> mobile.mycingular.com
Server: ns.yourisp.com
Address: 123.24.34.2

Non-authoritative answer:
mobile.mycingular.com preference = 10, mail exchanger = wcmx.mycingular.net

Authoritative answers can be found from:
mycingular.com nameserver = dns30.register.com
mycingular.com nameserver = dns29.register.com
> set qt
> wcmx.mycingular.net
Server: ns.yourisp.com
Address: 123.24.34.2

Non-authoritative answer:
wcmx.mycingular.net preference = 10, mail exchanger = wcmx.mycingular.net

Authoritative answers can be found from:
mycingular.net nameserver = atliserv1.mycingular.net
mycingular.net nameserver = atliserv2.mycingular.net
mycingular.net nameserver = iserv1.mycingular.net
mycingular.net nameserver = iserv2.mycingular.net
wcmx.mycingular.net internet address = 66.102.172.222
> ctrl-Z (or ctrl-D on unix)

So here’s the deal. I set query type (qt) to mail exchanger (mx). I lookup mobile.mycingular.com. I get one mail server, wcmx.mycingular.net. It didn’t tell me the IP address(es) of wcmx.mycingular.net, so I set the qt back to default and query that name. I get 66.102.172.222. Note that a domain can configure multiple MX with the same or different preferences. You are supposed to go through the preferences lowest to highest until you get one that works. Each fully qualified domain name (i.e. wcmx.mycingular.net) can have multiple IP addresses associated with it, you just pick whichever you want, and keep going until you find one that works. Ideally, all MX and all IP addresses will work, but this isn’t an ideal world.

Thanks 5cents. I didn’t even think of using my cell phone company’s mail server. I’ll give it a shot when I get home.

I was looking at PERL scripts, and they do seem relatively easy to navigate and understand. Definitely much more intuitive than the J2SE I was fiddling around with the other day.

However, one really easy question. Like I said, I’ve never worked with tasks that run in the background. Is it pretty trivial to set up a PERL program that checks my mail server ever five or ten minutes? (I’d be running this from my local computer, not on my abac.com space.) Is it just a matter of constructing a loop and letting it sit on my machine operating in the background, so that it checks my mail server, say, every time the minute ends in “0” or is this a back asswards way of doing it?
Plus, is there any disadvantage to checking mail at more frequent intervals?

On unix running stuff in the background is simple (with a few gotchas). Google unix daemon. On Windows I don’t think it is quite as easy, google windows service.

You don’t want to busy-loop, because you’ll waste all the CPU time on your one little background process. What you want to do is sleep. Sorry, I don’t know perl, but in Java you would use Thread.sleep(10601000) to sleep for 10 minutes. Assuming you have broadband and a non-ancient computer, the interval you choose for checking mail doesn’t matter much to you or your internet connection. It’s a fart in a windstorm. To your POP server, it probably won’t make much difference either, although if everybody using the POP server started checking their email every 3 seconds, I’d guess the load (network and CPU) on that POP server would go way up…

Use the Windows Task Scheduler, which is basically an interface on the old “at” command. This will allow you to kick off your process on schedule without having the process running an idle timer in between.
http://www.microsoft.com/windows2000/en/server/help/default.asp?url=/windows2000/en/server/help/agent_plus_at.htm

I entertained Windows Task Scheduler, but it doesn’t let you specify such frequent intervals as minutes…or does it?

If you are writing this program as a proxy, to sit between your mail client and the POP server, you want it to run all the time. You can use the scheduler to kick it off on bootup, but it is more elegant to make it a service. Here’s something that claims to support creating a Windows service in Perl: Roth Consulting's Official Win32::Daemon Home Page

What do you mean by an idle timer, btw? When you sleep(), you are really asleep. The OS will not run your process again until your sleep time is up. You are occupying memory, but that is all. Not CPU cycles were wasted while your process was asleep, and when it wakes up, it’s right where it was, no startup overhead or anything. For something that is getting run once a day? Sure, make that a task. For something that runs every 5 minutes, it really should be a service.

I’ve never even looked at the Task Scheduler because I’ve always used the AT command directly. It has one-minute granularity (some versions of AT had a bug that ignored seconds), but the Task Scheduler GUI only lets you set daily intervals for repeats. I always used a batch file with a loop to create all the AT commands I needed to run more frequent processes, but that’s probably a bad strategy in this case.

I believe the soon command will handle down to one-second repetitions, but I’ve never used it. I tend to use the sleep method mentioned by 5cents for processes I want to run more than once an hour since it avoids all the startup overhead. (which basically means I shouldn’t have started this diversion on scheduling options without thinking about how frequently you wanted to run your task…)

And 5cents, my “idle timer” comment was really aimed at pulykamell’s comment about using a loop, not at your suggestion for using sleep. Sorry for even bringing up the whole scheduler thing.

This would be the wrong way to approach it IMHO. It seems the ideal solution would be to hack up a perl backend with an appropriately defined protocol running through pipes and then worry about the front end at a later date. THis allows you to seperate policy from implementation and is a much cleaner design which is the model which SMTP, as well as countless other protocols, adheres to.

This means it would be trivial to bolt a java or html or even a bare front end to your program which allows you to experiment with lots of different languages without having to worry about re-coding the backend again.

Again, I maintain that Perl or one of it’s ilk (Python, ruby etc.) would be the best solution for the backend due to it’s superior string handling capabilities (kludging strings together in C or Java is almost painful after working with perl) and built in networking libraries.

The front end can be coded in whatever programming language du jour which features “Interactive, 3d, dynamic, global, scalable, enterprise, robust graphical capabilities”.

I would have agreed a few year ago, but Java now hasPerl-style regular expression classes. It’s a toss-up. Pick whichever one tickles your fancy.

Yes, but java regexes are ugly and horrible and stupid and ugly. Your embedding regexes inside strings so each escape charecter needs to be escaped as well. It gets even more hairy when your trying to find regexes inside a string using regexes.

eg:
perl: /^.*\s+cats $/
java: .match ("^.*\s+cats\ $")

perl: /\ \\/
java: .match(\\ \ \\\\)

I think.

s/java regexes/perl syntax/

:slight_smile: