Download Email Via Command Line

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Download Email Via Command Line

25 Dec 2020, 06:49

I'm wondering if there are any AHKers that have some scripts on this or recommended command line apps, for downloading email. Want to emphasize not sending email, but downloading. The best possibilities that I saw so far was Getmail and Fetchmail. However, didn't see any win32 binaries for Fetchmail, and Getmail is not only old, but seems to no longer work because of SSL requirements. Any suggestions or examples of what others might use or know of is welcome.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Download Email Via Command Line

25 Dec 2020, 08:32

Here is an AHK Outlook mail handler. Perhaps it can be expanded in its functionality.

https://www.autohotkey.com/boards/viewtopic.php?p=227299#p227299
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Download Email Via Command Line

25 Dec 2020, 14:38

mikeyww wrote:
25 Dec 2020, 08:32
Here is an AHK Outlook mail handler. Perhaps it can be expanded in its functionality.
Thanks for the suggestion, but that is kind of the opposite of what I'm looking for. Instead of a Microsoft Office solution, looking for e-mail clients that are lightweight, open-source, and could be used with various web email accounts (Gmail, Yahoo, Zoho, AOL, etc...). Some such alternative free open-source e-mail clients are Thunderbird, Sylpheen, and Claws. But, they are primarily GUI based. That group also kind of focuses on being Outlook replacements, so get a bit heavy in their footprint. The point of Getmail and Fetchmail were/are that they are command line based, so would be extremely lightweight. Such is much more flexible in terms of usage with a programming language like AHK. Also, if any GUI is needed, then that can also be built with AHK.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Download Email Via Command Line

26 Dec 2020, 08:44

Pop Client is more like what I mean. Telnet is a possibility, along as you are using it with ssl support. But it's quite talkative and often requires other things like providing BASE64, etc... Many of the command line e-mail clients have already took care of the annoying stuff, so you are more focused on e-mailing. However, as you noticed, you will often need to use Stunnel. Many of the command line e-mail clients are old-ish, and using unsecured ports and protocols. Pop Client and Stunnel works, and I'm presently testing others.

You can get the original Popclient from here- https://web.archive.org/web/20140709163500/http://www.codeode.com/popclient/popclient.zip
There is also a related topic that I had overlooked, but is relevant- https://autohotkey.com/board/topic/4239-command-line-e-mail-retrieval-with-ssl-support/

Along those lines, a person can use a category of software called an E-mail Notifier. These often don't download the entire e-mail. Various ones will have a Run File option, where upon alert of a certain type of e-mail, you can open your more full featured or open-source e-mail client (Winmail, Thunderbird, Sylpheed, Claws, etc...). The issue here is getting into GUIs that can be designed to not do what you want, where a command line e-mail client gives a lot of programmatic options for use with AHK. Also, various E-mail Notifiers are shareware and not true freeware or open-source. The ones that are open-source software may show a way to a totally AutoHotkey solution.
Last edited by SOTE on 26 Dec 2020, 08:53, edited 1 time in total.
User avatar
Jovannb
Posts: 268
Joined: 17 Jun 2014, 02:44
Location: Austria

Re: Download Email Via Command Line

26 Dec 2020, 08:52

Hi,

I'm using a tool which is called poplient.exe (e.g. to find in here >> https://autohotkey.com/board/topic/20112-command-line-pop-client-101/ << for getting/reading pop3-Emails with my AHK-Scripts.

regards

J.B.
AHK: 1.1.37.01 Ansi, 32-Bit; Win10 22H2 64 bit, german
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Download Email Via Command Line

26 Dec 2020, 08:58

Jovannb wrote:
26 Dec 2020, 08:52
I'm using a tool which is called poplient.exe
I think you mean popclient.exe, as oppose to poplient.exe. Yes, that's what ahk7 has also recommended. To work with various web e-mail, also need to use stunnel. Also, looking for any other command line email clients that work. So open to more suggestions.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Download Email Via Command Line

26 Dec 2020, 15:16

Another interesting program that is a kind of hybrid is PoptrayU. It's newer, open-source, and a derivative of an earlier program called Poptray. It's not a full e-mail client, but a light e-mail notifier for multiple web email servers that has command line options, and it can download specific e-mails. It's decent, but a little bit buggy. It has a plugin for SSL and TLS, so at least that part is taken care of and no need for Stunnel. Popclient and Stunnel are a good combination if a person is more interested in controlling things through AHK, but PoptrayU might be an option to consider or play with. https://sourceforge.net/projects/poptrayu/ (PoptrayU at SourceForge)
ahk7
Posts: 577
Joined: 06 Nov 2013, 16:35

Re: Download Email Via Command Line

26 Dec 2020, 15:58

Perhaps cygwin + getmail https://cygwin.com/packages/summary/getmail.html - there are portable versions of cygwin.
Lots of extra files of course with cygwin but the options seem to be rather limited when it comes to retrieving email (lots of options for sending though)

Have you have you considered WSL - https://docs.microsoft.com/en-us/windows/wsl/install-win10 - that way you can download emails using linux command line apps without jumping through too many hoops and the files will be accessible on your Windows drive for further processing anyway.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Download Email Via Command Line

12 Jan 2021, 11:01

For future reference, in case any other AHKers are curious or walk down this path...

For Popclient to work (can get here- https://web.archive.org/web/20140709163500/http://www.codeode.com/popclient/popclient.zip), you will likely need Stunnel (https://www.stunnel.org/downloads.html).

In the .xml file that is used with popclient (check directory of the executable), you have to configure the server to point towards your own computer (127.0.0.1). Note- You can also have the popclient config.xml code internal to your script, as a variable, so that your script reads it internally and not externally. Anyway, once you set it to 127.0.0.1, the traffic is directed through Stunnel. Then in Stunnel you configure the unencrypted port (this case 110) to be used with the standard encrypted port (usually 995).

Popclient Example

Code: Select all

	/*
		Server
		Specifies the address to the pop server. For example pop.mymailserver.com
	*/
	<Server>127.0.0.1</Server>

	/*
		Port
		Specifies the port to connect to on the server. Usually it is 110.
	*/
	<Port>110</Port>
Stunnel Example

Code: Select all

[yourmail-pop3]
client = yes
accept = 127.0.0.1:110
connect = pop.yourmail.com:995
verifyChain = yes
CAfile = ca-certs.pem
checkHost = pop.yourmail.com
OCSPaia = yes
Sadly, didn't see any posting of the popclient source code (for codeode's version). But there are some pop3client source code postings at codeprogect.com (source code is in C#).

https://www.codeproject.com/Articles/6062/A-POP3-Client-in-C-NET
https://www.codeproject.com/Articles/26007/POP3-Client
https://www.codeproject.com/Articles/125689/PopClient-A-POP3-companion-to-SmtpClient
Note- Original popclient, C source code, from which Fetchmail came from- https://github.com/soulwing/popclient
Note- PoptrayU source code is in Object Pascal and is at SourceForge- https://sourceforge.net/projects/poptrayu/files/Source%20Code/source%205.2.9.zip/download

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 345 guests