Pop3mail Hex VersionInline docsDeps Status

Pop3 client to download email (including attachments) from the inbox via the commandline or Elixir API.
Written in Elixir, using an Erlang pop3 client with SSL support derived from the epop package.
Decodes multipart content, quoted-printables, base64 and encoded-words.

Before you start

Gmail users:

Installation from scratch

Install Elixir

Follow the instructions on http://elixir-lang.org/install.html

Also install git and optionally also rebar3.

Clone project

$ git clone https://github.com/nico-amsterdam/pop3mail.git

Compile & unit test

$ cd pop3mail
$ mix deps.get
$ mix test

For usage, see usage chapter below.

Install in an Elixir project

  1. Add pop3mail and the erlang epop client to your list of dependencies in mix.exs:

    def deps do

     [{:pop3mail, "~> 1.2"}, 
      {:erlpop, github: "nico-amsterdam/erlpop"}]

    end

Upgrade instructions 1.1.0 to 1.2.0

Version 1.2.0 of Pop3mail consumes far less memory as 1.1.0 when handling big attachments. Erlpop now has additional functions epop_client.bin_retrieve and epop_message.bin_parse. Erlpop is backwards compatible.

Pop3mail requires the latest Erlpop. Run these commands to upgrade:

$ mix deps.update  erlpop
$ mix deps.compile erlpop

Pop3mail biggest changes:

Usage

Commandline script

The script downloads email and writes the content in the inbox folder.

$ pop3mail_downloader --help
$ pop3mail_downloader --username=<your email username> --password=<your email password> --max=10 --raw

or without shell/batch script:

*nix

$ mix run -e 'Pop3mail.CLI.main(["--help"])'
$ mix run -e 'Pop3mail.CLI.main(["--username=<your email username>", "--password=<your email password>", "--max=10", "--raw"])'

Windows

C:\pop3mail\mix run -e "Pop3mail.CLI.main([""--help""])"
C:\pop3mail\mix run -e "Pop3mail.CLI.main([""--username=<your email username>"", ""--password=<your email password>"", ""--max=10"", ""--raw""])"

The script defaults to Gmail, but you can specify other POP3 server and port settings.

Use in Elixir

Documentation is available online

Example:

$ iex -S mix

# notice that you must use single quotes here
iex(1)> {:ok, client} = :epop_client.connect('user@gmail.com', 'password', 
...(1)>   [:ssl, {:addr, 'pop.gmail.com'}, {:port, 995}, {:user, 'user@gmail.com'}])
iex(2)> :epop_client.stat(client) 
iex(3)> {:ok, mail_content} = :epop_client.bin_retrieve(client, 1) 
iex(4)> {:message, header_list, body_content } = :epop_message.bin_parse(mail_content)
iex(5)> Pop3mail.header_lookup(header_list, "Subject")
iex(6)> Pop3mail.header_lookup(header_list, "From")
iex(7)> Pop3mail.header_lookup(header_list, "Date")
iex(8)> part_list = Pop3mail.decode_body_content(header_list, body_content)
iex(9)> length(part_list)
iex(10)> part = Enum.at(part_list, 0)
iex(11)> part.media_type
iex(12)> part.filename
iex(13)> part.charset
iex(14)> part.content
iex(15)> :epop_client.delete(client, 1)
iex(16)> {:ok, mail_content} = :epop_client.bin_retrieve(client, 2) 
iex(17)> {:message, header_list, body_content } = :epop_message.bin_parse(mail_content)
iex(18)> Pop3mail.header_lookup(header_list, "Subject")
iex(19)> :epop_client.quit(client)

Spam folder

You better turn off the spam folder of your email account if you don't want to miss any email with this program. In Gmail you cannot turn it off, but you can create a filter for spam with the option 'Never send it to spam'.

Reset Gmail

Gmail remembers which mails are already read. Fortunetely Gmail can be reset to re-read all emails.

Login in www.gmail.com. In Gmail webmail Settings > Forwarding and POP/IMAP, select another option for POP, like Download mail from now on. Save change. Go back to settings and select Download all mail, Save change.

Now your email client should download all mail again.

Google unlock captcha

If you get an error 'web login required', push the 'Continue' button in the browser:

https://accounts.google.com/DisplayUnlockCaptcha

License

MIT

Acknowledgment

Thanks Erik Søe Sørensen for upgrading the Epop client to the latest Erlang version.