# Command line email tool

**URL:** <https://boards.straightdope.com/t/command-line-email-tool/564015>\
**Category:** Factual Questions\
**Created:** [December 13, 2010, 6:43pm UTC](https://boards.straightdope.com/t/command-line-email-tool/564015 "2010-12-13T18:43:17Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaxTheVool](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@MaxTheVool](https://boards.straightdope.com/u/MaxTheVool)\
**Post date:** [December 13, 2010, 6:43pm UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/1 "2010-12-13T18:43:17Z")

</div>

So I want to do some automated email processing (someone sends me an email with a particular subject line, and something automatic runs and sends an email back). I’m a professional programmer so I know what I’m doing with code, but I’ve never even remotely touched anything like this. So I’m hoping that there’s a command line email tool, where I could set something up that runs every 5 minutes where I call “getMyGMail.exe -username foo -password -bar”, that talks to GMail (or some other such free mail site) and dowloads all new emails into a directory. Then I can easily write code to scan the directory, process all the email, etc. Then I can run “sendGMail.exe” once for each email I want to send, wait 5 minutes, and repeat.

At least, that’s how I envision it.  
Anyone know of an easy way to do this?

thanks!

---

<div class="post-metadata">

**Author:** ![Disheavel](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Disheavel](https://boards.straightdope.com/u/Disheavel)\
**Post date:** [December 13, 2010, 7:13pm UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/2 "2010-12-13T19:13:05Z")

</div>

Most mail programs have much have this ability. If you are on a Mac, for instance, use the mail rules to scan incoming email and then have it call an AppleScript or Automator action that has the information for sending the return email.

Additionally, if you want command line tools Linux/Unix have built in tools for sending [mail](http://linux.about.com/od/commands/l/blcmdl1_Mail.htm), but a warning that I know people who have had trouble getting it through the internet in these days of authentication, etc.

---

<div class="post-metadata">

**Author:** ![AnalogSignal](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/analogsignal/32/1085_2.png) [@AnalogSignal](https://boards.straightdope.com/u/AnalogSignal)\
**Post date:** [December 13, 2010, 7:17pm UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/3 "2010-12-13T19:17:29Z")

</div>

For just sending email from the command line, I like Blat ([http://www.blat.net/](http://www.blat.net/)) but Blat doesn’t know how to check email so it’s only half of what you need.

---

<div class="post-metadata">

**Author:** ![MaxTheVool](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@MaxTheVool](https://boards.straightdope.com/u/MaxTheVool)\
**Post date:** [December 13, 2010, 7:18pm UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/4 "2010-12-13T19:18:44Z")

</div>

> [@Disheavel](#):
>
> Most mail programs have much have this ability. If you are on a Mac, for instance, use the mail rules to scan incoming email and then have it call an AppleScript or Automator action that has the information for sending the return email.
> 
> Additionally, if you want command line tools Linux/Unix have built in tools for sending [mail](http://linux.about.com/od/commands/l/blcmdl1_Mail.htm), but a warning that I know people who have had trouble getting it through the internet in these days of authentication, etc.

This is presumably on a PC, as that’s all I have immediate access to.

---

<div class="post-metadata">

**Author:** ![LionelHutz405](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lionelhutz405/32/536_2.png) [@LionelHutz405](https://boards.straightdope.com/u/LionelHutz405)\
**Post date:** [December 13, 2010, 7:19pm UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/5 "2010-12-13T19:19:24Z")

</div>

[http://www.chilkatsoft.com/](http://www.chilkatsoft.com/)

‘Mail Command’ (last one in first column) is a command line one.  
Lots of other email stuff there if you are looking to build your own app.

---

<div class="post-metadata">

**Author:** ![Fubaya](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@Fubaya](https://boards.straightdope.com/u/Fubaya)\
**Post date:** [December 13, 2010, 8:56pm UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/6 "2010-12-13T20:56:29Z")

</div>

There is also a sendmail for windows. I’m not sure if it’s a port of the unix sendmail or completely different. I use sendmail on linux to send through gmail, so you shouldn’t have any problems authenticating gmail with a good client.

---

<div class="post-metadata">

**Author:** ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)\
**Post date:** [December 13, 2010, 8:56pm UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/7 "2010-12-13T20:56:53Z")

</div>

If a simple scan for keywords will suffice and you don’t need programmatic logic, Gmail itself [can do this](http://gigaom.com/collaboration/3-handy-uses-for-gmails-canned-responses-feature/) using the “filters” and “canned responses” features.

---

<div class="post-metadata">

**Author:** ![Kyrie\_Eleison](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/kyrie_eleison/32/7682_2.png) [@Kyrie\_Eleison](https://boards.straightdope.com/u/Kyrie_Eleison)\
**Post date:** [December 13, 2010, 9:20pm UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/8 "2010-12-13T21:20:44Z")

</div>

You said PC, but you didn’t specify what OS. If you’re willing to go the Linux route, [fetchmail](http://fetchmail.berlios.de/) and [procmail](http://www.procmail.org/) are the tools you’re looking for.

---

<div class="post-metadata">

**Author:** ![UncleRojelio](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/unclerojelio/32/3160_2.png) [@UncleRojelio](https://boards.straightdope.com/u/UncleRojelio)\
**Post date:** [December 13, 2010, 9:43pm UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/9 "2010-12-13T21:43:07Z")

</div>

> [@Kyrie\_Eleison](#):
>
> [procmail](http://www.procmail.org/)

Now that’s a tool I hadn’t thought of in ages. It will definitely do what the OP wants, provided he has the perseverance to beat it into submission first.

---

<div class="post-metadata">

**Author:** ![Erasmus\_Darwin](https://avatars.discourse-cdn.com/v4/letter/e/c57346/32.png) [@Erasmus\_Darwin](https://boards.straightdope.com/u/Erasmus_Darwin)\
**Post date:** [December 14, 2010, 1:11am UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/10 "2010-12-14T01:11:17Z")

</div>

If I were doing this, I’d throw together a small script that takes advantage of IMAP’s IDLE command. Gmail supposedly supports it, and it would allow you to watch for new messages without having to actively poll their servers for new messages.

If you’re familiar with Perl, then you can let [Mail::IMAPClient](http://search.cpan.org/~plobbes/Mail-IMAPClient-3.25/lib/Mail/IMAPClient.pod) do most of the dirty work for you.

---

<div class="post-metadata">

**Author:** ![Gary\_Robson](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/gary_robson/32/3448_2.png) [@Gary\_Robson](https://boards.straightdope.com/u/Gary_Robson)\
**Post date:** [December 14, 2010, 5:18pm UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/11 "2010-12-14T17:18:41Z")

</div>

PHP has a lot of email handling tools in the standard installation, and it runs on Unix, Linux, Mac, and Windows. The string handling (for doing the filtering) isn’t as good as Perl, but it’s still pretty powerful and easy to use.

---

<div class="post-metadata">

**Author:** ![MaxTheVool](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@MaxTheVool](https://boards.straightdope.com/u/MaxTheVool)\
**Post date:** [December 22, 2010, 11:40pm UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/12 "2010-12-22T23:40:50Z")

</div>

I’ve finally figured this out, and it’s (to me) fairly hilariously complex.

For getting the emails, I’ve installed cygwin, and am using fetchmail, which itself uses procmail. This gets all the emails into a mailbox file, which I can then open up with my C code and clumsily parse.

For sending the emails, I’m basically using the instructions found [here](http://www.jeffkastner.com/2010/01/blat-stunnel-and-gmail/), which involve two entirely different programs, namely stunnel and blat.

---

<div class="post-metadata">

**Author:** ![Gary\_Robson](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/gary_robson/32/3448_2.png) [@Gary\_Robson](https://boards.straightdope.com/u/Gary_Robson)\
**Post date:** [December 23, 2010, 12:51am UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/13 "2010-12-23T00:51:55Z")

</div>

If it works, and your solution uses tools you’re comfortable with, then hoorah! Don’t worry about whether you (or others) find it hilariously complex.

---

<div class="post-metadata">

**Author:** ![qazwart](https://avatars.discourse-cdn.com/v4/letter/q/5fc32e/32.png) [@qazwart](https://boards.straightdope.com/u/qazwart)\
**Post date:** [December 23, 2010, 7:32am UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/14 "2010-12-23T07:32:59Z")

</div>

Long ago in a galaxy far far away, Unix had a “filter” command. In the old email setup, you had vacation mode. In vacation mode, you could put text what you wanted to say when someone mailed you, or you could put a pipe to a program.

The “filter” command allowed you to easily parse email messages for sender, subject, etc. You setup your [vacation](http://manpages.unixforum.co.uk/man-pages/linux/suse-linux-10.1/1/vacation-man-page.html) program to use the filter command, and then setup a configuration file for the filter command to use. I wonder if it’s still there.

This was back in the days when people argued whether you used mailx or [Elm](http://en.wikipedia.org/wiki/Elm_(e-mail_client)) as your mail client. Real programmers wouldn’t be caught using Elm because it had a menu. Real men knew how to type in the arcane one and two letter mailx commands and knew how to customize their .mailrc file. And, I’m not even going to say anything about the people who used [Pine](http://en.wikipedia.org/wiki/Pine_(e-mail_client)).

Yes sir, those were the days when men were men, and women were… completely uninterested in us…

---

<div class="post-metadata">

**Author:** ![alaham](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@alaham](https://boards.straightdope.com/u/alaham)\
**Post date:** [December 23, 2010, 9:34am UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/15 "2010-12-23T09:34:28Z")

</div>

> [@MaxTheVool](#):
>
> sending the emails, I’m basically using the instructions found [here](http://www.jeffkastner.com/2010/01/blat-stunnel-and-gmail/), which involve two entirely different programs, namely stunnel and blat.

I use the VBscript at [http://cybernetnews.com/vbscript-send-emails-using-gmail/](http://cybernetnews.com/vbscript-send-emails-using-gmail/) . I had been using blat for command-line emailing in Windows, but it doesn’t seem to support SSL, required by Gmail.

---

<div class="post-metadata">

**Author:** ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)\
**Post date:** [December 23, 2010, 9:43am UTC](https://boards.straightdope.com/t/command-line-email-tool/564015/16 "2010-12-23T09:43:20Z")

</div>

MaxTheVool, out of curiosity, did you ever look into Gmail’s canned responses and filters? Did they lack the functionality you needed?
