Command line utility for https://protonmail.com
System dependencies (Probably everything's already installed)
sudo apt install -y xvfb python3-pip firefox # on debian
sudo dnf install xorg-x11-server-Xvfb python3-pip firefox # on fedora
sudo pacman -S xorg-server-xvfb python-pip firefox wget # on arch
Geckodriver
# Find your release: https://github.com/mozilla/geckodriver/releases
# for linux x64
wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
sudo tar -xvf geckodriver-*.tar.gz -C /usr/local/bin/ ; rm geckodriver-*.tar.gz
Protonmail CLI
git clone https://github.com/dimkouv/protonmail-cli /opt/protonmail-cli
ln -s /opt/protonmail-cli/protonmail-cli.py /bin/protonmail-cli
pip3 install -r /opt/protonmail-cli/requirements.pip
# show full usage
protonmail-cli --help
# each sub-command has its own `--help` section.
# list inbox - print latest mails
protonmail-cli list -t inbox
protonmail-cli list -t spam
# check inbox for new mails
protonmail-cli check
# send mail
protonmail-cli send \
-t "one@protonmail.com" \
-t "two@pm.me" \
-s "my subject" \
-b "my mail message" \
--html # (optional if you want to render body as html) \
-a "/path/to/file.jpg" \ # (optional for adding attachments)
-a "/path/to/other/file.pdf"
Global settings, including user credentials, can be specified on /opt/protonmail-cli/protonmail/settings.py
User credentials can also be set in their own file, overriding those found inside
settings.py
. The global argument --credential
allow you to set the file path of
this config file. This would allow better security by allowing each user of a multi-users
machine to keep their credentials inside their home folder.
If user credentials are not specified in settings.py
or credentials file
then cli prompts you to type them.
Example usage of separate credentials file
# /home/user/protonmailcli.ini
[credential]
username = mymail@protonmail.com
password = mysafepass
protonmail-cli --credential /home/user/protonmailcli.ini list
For even better security, chmod 600
this file, so only the user launching the
application can read it.
Simply run protonmail-cli
without any parameters to open an interactive session.
[Anonymous] Choose an option from the menu
m : Shows this menu
x : Exit
l : Login
> l
ProtonMail email or username: dimkouv
ProtonMail password:
Loading...
Welcome dimkouv
[dimkouv] Choose an option from the menu
m : Shows this menu
x : Exit
e : Logout
inbox : Show inbox mails
drafts : Show drafts
sent : Show sent mails
starred : Show starred mails
archive : Show archived mails
spam : Show spam mails
trash : Show trash mails
allmail : Show all mails
>
Core functions can be called directly from your code instead of using protonmail-cli
pip3 install git+https://github.com/dimkouv/protonmail-cli
Usage example
import protonmail
client = protonmail.core.ProtonmailClient()
client.login("mymail@protonmail.com", "mypassword")
# send mails
client.send_mail(
["one@protonmail.com", "two@pm.me"],
"subject",
"my mail message"
)
# send mails as html
client.send_mail(
["one@protonmail.com", "two@pm.me"],
"subject",
"""
<h1>hello friend</h1>
<p>This message was sent from <strong>protonmail-cli</strong></p>
""",
as_html=True
)
# upload attachments
client.send_mail(
...,
attachments=[
'/path/to/file.jpg',
'/path/to/other/file.pdf'
]
)
# read mails
mails = client.get_mails("inbox")
spam = client.get_mails("spam")
# check for new mail
has_new_mail = client.has_new_mail()
client.destroy()
cd protonmail-cli
virtualenv -p python3 venv
source venv/bin/activate
pip install .
python3 tests/core_test.py