A working full-stack OAuth2 + offline + queueing email container!
1.3K
Part of the CYA Project : https://github.com/v4tech/cya-project
Goals
| Goal | Done | tl;dr |
|---|---|---|
| I want to be able to backup my cloud based email to a local machine - using OAuth2 | :white_check_mark: | OfflineIMAP below |
| I want to be able to send email from my local machine - using OAuth2 | :white_check_mark: | send.py below |
| I will not use passwords or turn on "Allow insecure apps" - I will use OAuth2 (or better!) | :white_check_mark: | |
| I want to be able to search and read messages whilst offline | :white_check_mark: | see notmuch |
| I want to be be able to reply to my email when I'm offline (i.e. queue) | :white_check_mark: | msmtpq below |
docker pull v4tech/cya-email
wget https://raw.githubusercontent.com/v4tech/cya-project/master/cya-dockerfunc.sh
source cya-dockerfunc.sh
offlineimapsend.py pretending to be msmtpmsmtpqOAuth2 aware email sync - www.offlineimap.org
Mapped as command offlineimap
docker run --rm \
--name email
-v ${HOME}/offlineimap.conf:/home/mymail/.offlineimaprc:ro \
-v ${HOME}/Mail:/home/mymail/Mail \
v4tech/cya-email \
fetch-messages.sh
OAuth2 aware email sending - https://github.com/cscorley/send.py
Mapped as commands send.py and (wrapper) msmtp
This section is only really useful if you want to send a message now. For queueing and sending later see the msmtpq section below.
NOTE: I've written a wrapper called msmtp to make this interact with msmtpq transparently.
docker run --rm -i \
-v ${HOME}/sendpyrc:/home/mymail/.sendpyrc:ro
v4tech/cya-email \
msmtp
Look at the example given by Christopher Corley, but remember to change his send.py --readfrommsg to msmtp.
Test your email by doing this (change the email addresses first, silly):
echo "From: Christopher S. Corley <[email protected]>
To: Test <[email protected]>
Subject: Test message
`
Body would go here
" | msmtp
Message queue for msmtp - https://github.com/project-mir/mir.msmtpq
Mapped as command msmtpq
I'm cheating and using msmtpq to queue messages to send with send.py. In JVR's post he mentions patching mir.msmtpq, but I've just added a wrapper script.
docker run --rm -i \
-v ${HOME}/sendpyrc:/home/mymail/.sendpyrc:ro \
-v ${HOME}/msmtpq-queue:/home/mymail/.config/msmtpq/queue \
v4tech/cya-email \
msmtpq
~/.config/msmtpq/queue. Remember to mount this externally.Queue a message:
echo "From: Christopher S. Corley <[email protected]>
To: Test <[email protected]>
Subject: Test message
Body would go here
" | msmtpq
Check the queue:
msmtpq --manage list
See...it's there...
Key: 920cce313eb9095a463f00a7b711d1a224756879
Args: []
From: Christopher S. Corley <[email protected]>
To: Test <[email protected]>
Subject: Test message
Body would go here
So then send it:
msmtpq --manage send
You really should read Google's OAuth2DotPyRunThrough.
There are effectively two steps:
To use OAuth2, you must have registered your application through the Google APIs Console. Registration is explained in Using OAuth 2.0 to Access Google APIs.
After registering your application, go to the "API Access" tab and create a Client ID.
oauth2.pyis designed to work with the "Installed application" application type. After creating a Client ID, the API Access tab should show a Client ID and Client secret. You will need to supply these values tooauth2.pyin the next step.
Run the following command - using your client_id and client_secret:
docker run --rm -it v4tech/cya-email \
python /home/mymail/gmail-oauth2-tools/python/oauth2.py \
--generate_oauth2_token --client_id=364545978226.apps.googleusercontent.com \
--client_secret=zNrNsBzOOnQy8_O-8LkofeTR
The output will be something like:
To authorize token, visit this url and follow the directions:
https://accounts.google.com/o/oauth2/auth?client_id=364545978226.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fmail.google.com%2F
Enter verification code:
Visit the URL in your browser. You may need to login to Google. Then you should see a request to grant access to your application. Done!
Things I still need to do - or creat links to solutions elsewhere:
You'll have to work out what ${HOME}/sendpyrc, etc., means in your system. I don't do Windows.
Content type
Image
Digest
Size
53 MB
Last updated
over 8 years ago
docker pull v4tech/cya-email