You are not logged in.

#1 2026-08-30 11:22:28

jpka
Member
Registered: 2024-12-04
Posts: 10

"You have mail" check via command line [SOLVED]

Hello.

I am "just" need to know if I am have new messages at remote pop3 server, with results (return values set) of: There is mail, No mail, and Error occured. (Via return code, or via temp file content)
Like `xfce4-mailwatch-plugin` provides, but, with command line.
No need to read or send mails via CLI. It should be one-command, non interactive, using standard tool. It can be not fast, but preferably with no more than one minute timeout, should terminate with error then.
I've noticed that there is no package provides `mail` command; anyway I have no idea if `mail` is suitable.
What I found working so far, is interactive one, like

    openssl s_client -quiet -connect remote_ip:110 -starttls pop3
    ...
    +OK Dovecot ready.
    USER me
    +OK
    PASS me_again
    +OK Logged in.
    LIST
    +OK 1 messages:
    1 154796
    .
    QUIT
    +OK Logging out

While it probably can be converted to automated one using bash script, i am expect that it is solved already with some CLI tool(s) comes with Archlinux. Please suggest me some.
There is a lot of general search results how to send mails, but, just a few for receive, and nothing for just check, I am found so far.

Thanks!

P.S. I am sorry if this general section is incorrect place for ask about software suggestion; I can't find more particular suggestions section at forums here at Archlinux.

Last edited by jpka (Today 13:42:55)

Offline

#2 2026-08-30 12:55:40

cryptearth
Member
Registered: 2024-02-03
Posts: 2,310

Re: "You have mail" check via command line [SOLVED]

first: i would use imap instead of pop - because of IDLE command: with imap you connect once, issue an idle command and have the server inform you when it got new mail; with pop you have to keep polling - that's something from the past

as for the tool itself: i would go for something on my own - the mail procols, namely smtp, imap4 and pop3, are so old and well established there're well tested libs out there for pretty much any lamguage - using such lib along with imap idle and some notification can be done in 20-30 lines, nothin special

or: just get a regular mail client like thunderbird

Offline

#3 2026-08-30 15:06:56

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,636

Re: "You have mail" check via command line [SOLVED]

Yes is and has - you're also almost there  and only have to feed some input into openssl s_client and read the output (technically you need this to be interactive but if you don't tell anyone: you can just stray in some tactical "sleep" to wait for the server's response wink)

Otherwise there's eg https://perldoc.perl.org/Net::POP3 - as
Then there's https://archlinux.org/packages/extra/x86_64/mpop/

For imap there'd eg. be https://archlinux.org/packages/extra/x8 … mapnotify/ but how the fuck can that be 9MB??
=> See eg https://metacpan.org/release/PLOBBES/Ma … es/idle.pl

or: just get a regular mail client like thunderbird

https://archlinux.org/packages/extra/x86_64/mutt/ is smaller than that go monstrosity (and most of that is the documentation), works on the console and can fire random scripts when new mail arrives.
It also supports imap and pop3 and you get to look at the mail and delete the spam as well smile

Oh, and then there's of course https://man.archlinux.org/man/mail.1#e

pacman -F mail # or search the database for "nail" to find a dad joke

Offline

#4 Yesterday 20:52:32

jpka
Member
Registered: 2024-12-04
Posts: 10

Re: "You have mail" check via command line [SOLVED]

Hello.

@cryptearth, @seth, thanks for your answers. These solutions looks good, I've tested it. Turns out that most are requires set up of some local mailbox, which I am try to avoid. I've have Thunderbird already, but the goal is not to use it as notifier, as TB becomes too CPU hungry today, even when idle; I try to find something tiny to watch for mail 24/7, then start TB by hands when need.

There is 'fetchmail' companion for mail (s-nail), it looks pretty good, works w/o mbox (afaics), yet have --check option, which is exactly what I need. Sadly, it does not work with encryption:

echo 'poll remote_IP proto IMAP user "me" pass "me" ssl sslcertpath "/etc/ssl"' > .fetchmailrc
fetchmail -v

spent whole day, try other seat and various sslcertpath/sslcertfile, but still stucks with

fetchmail: Server certificate verification error: self-signed certificate
fetchmail: Missing trust anchor certificate:

which was reported several times, but no solution so far. I think my local cert tree is correct, as curl/wget/browsers/pacman/Thunderbird/openssl command above, are all works well. If it's mailserver side trouble, why then openssl example above works with this server.
I'll continue this research, will look deeply into each of mentioned solutions, and will report.

Thanks again!

P.S. For this task, I prefer ready-to-use packages if possible (compared to own bash/perl scripts).
Yes, I will try some spells to transform openssl command above to automated bash script, but it is not easy then to include it into my ultimate simple C code (or, I need to use openssl lib at my C code, but it's then reinvention of fetchmail...)

Offline

#5 Yesterday 21:39:16

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,636

Re: "You have mail" check via command line [SOLVED]

What failed about

mpop --tls -s --delivery mbox,/dev/null --host pop3.fakemail.com --user jpka@fakemail.com --passwordeval='echo supersecretpassword'

?

Offline

#6 Yesterday 21:52:38

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 774

Re: "You have mail" check via command line [SOLVED]

jpka wrote:

While it probably can be converted to automated one using bash script, i am expect that it is solved already

Just in case you decide to automate POP3 or similar text based protocol, there is expect tool.

Offline

#7 Today 13:42:28

jpka
Member
Registered: 2024-12-04
Posts: 10

Re: "You have mail" check via command line [SOLVED]

Hello.

@seth, @dimich, thanks for your information.

With help of `mpop`, I was able to find where was a trouble:

mpop --serverinfo --tls --tls-certcheck=off --host=remote_server

Which shows the server side cert is way outdated. What a mess. (This remote cert check may be obvious, but I am new with it, never fall into such a bad mailserver cert yet)
The reason why

openssl s_client... 

still works fine, is somewhat relaxed its default behaviour, due to it is tool for tests, not for everyday use one.

I can't fix remote server now. But, both `fetchmail` and `mpop` are have (not recommended) skip of this check:

mpop --tls --tls-certcheck=off -s --delivery mbox,/dev/null --host remote_server --user me --passwordeval='echo me'

fetchmail -c --nosslcertck  # See its .rc file example above

which now works fine, yet still keeps data channel secure (looks like).

Thanks again!

Offline

#8 Today 15:15:15

cryptearth
Member
Registered: 2024-02-03
Posts: 2,310

Re: "You have mail" check via command line [SOLVED]

welcome to the world of x.509 and pki
fun fact: just having a few certificates around is one thing, but when you start setting up a full pki with crl/ocsp and layering - oh, that's quite some fun ... not

btw

that most are requires set up of some local mailbox

don't know where you got that from - but it's not correct for a simple checker but is likely due to you looked at full mail clients (although - at least mutt does not require a local mailbox) - but some 10-liner just connecting to an imap server, linger with idle, some heartbeat to keep the connection alive and some info popup (ok, now we're at about 30 lines) doesn't need any local storage as all it gets is a server event telling it "hey, there's new mail"

Offline

Board footer

Powered by FluxBB