# SMTP Crash Course

**URL:** <https://boards.straightdope.com/t/smtp-crash-course/234594>\
**Category:** Factual Questions\
**Created:** [March 16, 2004, 5:28am UTC](https://boards.straightdope.com/t/smtp-crash-course/234594 "2004-03-16T05:28:49Z")\
**Posts on this page:** 15\
**Page:** 2

<div class="post-metadata">

**Author:** ![5cents](https://avatars.discourse-cdn.com/v4/letter/5/46a35a/32.png) [@5cents](https://boards.straightdope.com/u/5cents)\
**Post date:** [March 16, 2004, 8:00pm UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/21 "2004-03-16T20:00:37Z")

</div>

> [@pulykamell](#):
>
> I want to write a small application that runs in the background, checks my pop3 servers every ten minutes or so. If it finds messages that conform to certain criteria, it will then email my mobile phone and send a text message with some basic info plus the first few lines of the message. (Yes, I know there’s probably programs out there or mobile packages that will let me do this, but just for education’s sake I’d like to do this.)

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

telnet [pop.comcast.net](http://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](http://www.faqs.org/rfcs/rfc1939.html). 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.

---

<div class="post-metadata">

**Author:** ![5cents](https://avatars.discourse-cdn.com/v4/letter/5/46a35a/32.png) [@5cents](https://boards.straightdope.com/u/5cents)\
**Post date:** [March 16, 2004, 8:12pm UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/22 "2004-03-16T20:12:55Z")

</div>

> [@pulykamell](#):
>
> Any comments about Java J2SE?

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](http://java.sun.com/docs/books/tutorial/information/download.html). Just get tutorial.zip, as it contains everything.

---

<div class="post-metadata">

**Author:** ![pulykamell](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/pulykamell/32/3166_2.png) [@pulykamell](https://boards.straightdope.com/u/pulykamell)\
**Post date:** [March 16, 2004, 8:13pm UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/23 "2004-03-16T20:13:56Z")

</div>

> [@5cents](#):
>
> It appears that you were trying to send email from outside [abac.com](http://abac.com) to somewhere else outside [abac.com](http://abac.com), but using the mail server at [abac.com](http://abac.com) to pass the message along. This is called relaying, and nobody in their right mind allows this anymore (unless you authenticate).

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](mailto:username@soandso.com) \<unverified\>”

I do have an account with [abac.com](http://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.

---

<div class="post-metadata">

**Author:** ![5cents](https://avatars.discourse-cdn.com/v4/letter/5/46a35a/32.png) [@5cents](https://boards.straightdope.com/u/5cents)\
**Post date:** [March 16, 2004, 8:27pm UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/24 "2004-03-16T20:27:58Z")

</div>

> [@CompuHyperGlobalMegaNet](#):
>
> Using Java is about on par with using C++ in terms of difficulty.

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…

---

<div class="post-metadata">

**Author:** ![5cents](https://avatars.discourse-cdn.com/v4/letter/5/46a35a/32.png) [@5cents](https://boards.straightdope.com/u/5cents)\
**Post date:** [March 16, 2004, 10:05pm UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/25 "2004-03-16T22:05:47Z")

</div>

> [@pulykamell](#):
>
> I do have an account with [abac.com](http://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.

Here’s how SMTP authentication works ([RFC 2554](http://www.faqs.org/rfcs/rfc2554.html)) and here is [examples](http://small.dropbear.id.au/myscripts/postfixmysql.html) 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](http://abac.com), and it doesn’t give me back any AUTH mechanisms, so I would have to say no, [abac.com](http://abac.com) doesn’t support SMTP AUTH.

> [@](#):
>
> 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.

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](http://ns.yourisp.com)  
Address: 123.24.34.2

\> set qt=mx  
\> [mobile.mycingular.com](http://mobile.mycingular.com)  
Server: [ns.yourisp.com](http://ns.yourisp.com)  
Address: 123.24.34.2

Non-authoritative answer:  
[mobile.mycingular.com](http://mobile.mycingular.com) preference = 10, mail exchanger = [wcmx.mycingular.net](http://wcmx.mycingular.net)

Authoritative answers can be found from:  
[mycingular.com](http://mycingular.com) nameserver = [dns30.register.com](http://dns30.register.com)  
[mycingular.com](http://mycingular.com) nameserver = [dns29.register.com](http://dns29.register.com)  
\> set qt  
\> [wcmx.mycingular.net](http://wcmx.mycingular.net)  
Server: [ns.yourisp.com](http://ns.yourisp.com)  
Address: 123.24.34.2

Non-authoritative answer:  
[wcmx.mycingular.net](http://wcmx.mycingular.net) preference = 10, mail exchanger = [wcmx.mycingular.net](http://wcmx.mycingular.net)

Authoritative answers can be found from:  
[mycingular.net](http://mycingular.net) nameserver = [atliserv1.mycingular.net](http://atliserv1.mycingular.net)  
[mycingular.net](http://mycingular.net) nameserver = [atliserv2.mycingular.net](http://atliserv2.mycingular.net)  
[mycingular.net](http://mycingular.net) nameserver = [iserv1.mycingular.net](http://iserv1.mycingular.net)  
[mycingular.net](http://mycingular.net) nameserver = [iserv2.mycingular.net](http://iserv2.mycingular.net)  
[wcmx.mycingular.net](http://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](http://mobile.mycingular.com). I get one mail server, [wcmx.mycingular.net](http://wcmx.mycingular.net). It didn’t tell me the IP address(es) of [wcmx.mycingular.net](http://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](http://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.

---

<div class="post-metadata">

**Author:** ![pulykamell](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/pulykamell/32/3166_2.png) [@pulykamell](https://boards.straightdope.com/u/pulykamell)\
**Post date:** [March 16, 2004, 10:17pm UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/26 "2004-03-16T22:17:54Z")

</div>

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](http://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?

---

<div class="post-metadata">

**Author:** ![5cents](https://avatars.discourse-cdn.com/v4/letter/5/46a35a/32.png) [@5cents](https://boards.straightdope.com/u/5cents)\
**Post date:** [March 16, 2004, 10:36pm UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/27 "2004-03-16T22:36:10Z")

</div>

> [@pulykamell](#):
>
> 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](http://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(10_60_1000) 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…

---

<div class="post-metadata">

**Author:** ![micco](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@micco](https://boards.straightdope.com/u/micco)\
**Post date:** [March 16, 2004, 10:51pm UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/28 "2004-03-16T22:51:57Z")

</div>

> [@pulykamell](#):
>
> 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?

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](http://www.microsoft.com/windows2000/en/server/help/default.asp?url=/windows2000/en/server/help/agent_plus_at.htm)

---

<div class="post-metadata">

**Author:** ![pulykamell](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/pulykamell/32/3166_2.png) [@pulykamell](https://boards.straightdope.com/u/pulykamell)\
**Post date:** [March 16, 2004, 11:05pm UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/29 "2004-03-16T23:05:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![5cents](https://avatars.discourse-cdn.com/v4/letter/5/46a35a/32.png) [@5cents](https://boards.straightdope.com/u/5cents)\
**Post date:** [March 16, 2004, 11:26pm UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/30 "2004-03-16T23:26:11Z")

</div>

> [@micco](#):
>
> 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](http://www.microsoft.com/windows2000/en/server/help/default.asp?url=/windows2000/en/server/help/agent_plus_at.htm)

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](http://www.roth.net/perl/Daemon/)

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.

---

<div class="post-metadata">

**Author:** ![micco](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@micco](https://boards.straightdope.com/u/micco)\
**Post date:** [March 16, 2004, 11:36pm UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/31 "2004-03-16T23:36:17Z")

</div>

> [@pulykamell](#):
>
> I entertained Windows Task Scheduler, but it doesn’t let you specify such frequent intervals as minutes…or does it?

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](http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/soon-o.asp) 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.

---

<div class="post-metadata">

**Author:** ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)\
**Post date:** [March 17, 2004, 8:26am UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/32 "2004-03-17T08:26:55Z")

</div>

> [@micco](#):
>
> The big difference between using Java and using Perl for this project will be if you want to put a GUI on your app. Java has lots of GUI options. Programmers complain a lot about them, but basically you can do anything you want with Swing, SWT and even the old AWT. There are several ways to tack GUIs on Perl, but they’ve always felt quite kluged to me. I use Perl a lot for admin scripts, and it’s the best language available for a lot of tasks, but if you want shiny baubles like GUIs, I’d use something else.

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”.

---

<div class="post-metadata">

**Author:** ![5cents](https://avatars.discourse-cdn.com/v4/letter/5/46a35a/32.png) [@5cents](https://boards.straightdope.com/u/5cents)\
**Post date:** [March 17, 2004, 2:35pm UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/33 "2004-03-17T14:35:20Z")

</div>

> [@Shalmanese](#):
>
> 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.

I would have agreed a few year ago, but Java now has[Perl-style regular expression classes](http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/package-summary.html). It’s a toss-up. Pick whichever one tickles your fancy.

---

<div class="post-metadata">

**Author:** ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)\
**Post date:** [March 20, 2004, 5:00am UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/34 "2004-03-20T05:00:38Z")

</div>

> [@5cents](#):
>
> I would have agreed a few year ago, but Java now has[Perl-style regular expression classes](http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/package-summary.html). 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.

---

<div class="post-metadata">

**Author:** ![5cents](https://avatars.discourse-cdn.com/v4/letter/5/46a35a/32.png) [@5cents](https://boards.straightdope.com/u/5cents)\
**Post date:** [March 20, 2004, 6:11am UTC](https://boards.straightdope.com/t/smtp-crash-course/234594/35 "2004-03-20T06:11:55Z")

</div>

> [@Shalmanese](#):
>
> Yes, but java regexes are ugly and horrible and stupid and ugly.

s/java regexes/perl syntax/

🙂

[Previous page](https://boards.straightdope.com/t/smtp-crash-course/234594.md?page=1)
