Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 201: Docker support for building and running #381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SethRobertson
Copy link

To actually compile, I had to make a change to build.xml (presumably because I don't know enough about java) which I did not include. Similarly, I created an "entrypoint" file which specified the CLASSPATH (and didn't use any of non-relevant code paths from the davmail shell script).

The build.xml patch is shown below:

diff --git a/build.xml b/build.xml
index d1a967c7..869f4a10 100644
--- a/build.xml
+++ b/build.xml
@@ -119,6 +119,9 @@


  •           <fileset dir="/usr/share/java">
    
  •             <include name="**/*.jar" />
    
  •           </fileset>
           </classpath>
       </javac>
    

To actually compile, I had to make a change to build.xml (presumably
because I don't know enough about java) which I did not include.
Similarly, I created an "entrypoint" file which specified the
CLASSPATH (and didn't use any of non-relevant code paths from the
davmail shell script).

The build.xml patch is shown below:

diff --git a/build.xml b/build.xml
index d1a967c7..869f4a10 100644
--- a/build.xml
+++ b/build.xml
@@ -119,6 +119,9 @@
             <exclude name="davmail/exchange/auth/*Interactive*" unless="is.javafx"/>
             <classpath>
                 <path refid="classpath"/>
+               <fileset dir="/usr/share/java">
+                 <include name="**/*.jar" />
+               </fileset>
             </classpath>
         </javac>
     </target>
@esabol
Copy link

esabol commented Jan 15, 2025

@SethRobertson : To format your above post for GitHub properly, you should put three backticks (```) on a line by itself before and then again after your patch (diff output).

P.S. This is awesome! Thank you!

mguessan added a commit that referenced this pull request Feb 16, 2025
@Robin-Sch
Copy link

Robin-Sch commented Feb 17, 2025

Here is how I achieved headless (in docker), even working with oauth2:

Running headless

Connect to your vps (or equivalent) and run the commands below:

git clone https://github.com/mguessan/davmail
cd davmail
ant # if command not found, "apt install ant" or equivalent
tar -cf davmail-compile.tar -C $(pwd)/dist .
mv davmail-compile.tar src/contribs/docker
cd src/contribs/docker
chmod +x entrypoint
# change DAVMAIL_SERVER to yes in entrypoint
docker build . -t davmail

Then save the server config from here as davmail.properties and start the container using the command below:

docker run -p 1025:1025 -p 1143:1143 -v davmail.properties/davmail.properties davmail

(note that this will expose port 1025 and 1143 for everyone to use, change to your likings)

For a proper setup, make sure to move the davmail.properties to for example ~/docker/davmail and put the docker command as a docker compose file, or a bash file, whatever you want. Afterwards you can clean up the repo directory downloaded by git clone by just rm -rfing it.

But wait.... Oauth2 doesn't work on headless right?

Running in headless mode does not support logging in using oauth2. So what I did is that I ran the same steps above on my normal computer (which can run the GUI):

git clone https://github.com/mguessan/davmail
cd davmail
ant # if command not found, "apt install ant" or equivalent
tar -cf davmail-compile.tar -C $(pwd)/dist .
mv davmail-compile.tar src/contribs/docker
cd src/contribs/docker
chmod +x entrypoint
docker build . -t davmail

And then start the container using

docker run --network=host --rm --name davmail -v /tmp/.X11-unix:/tmp/.X11-unix -e JAVA_OPT_USER=-Dsun.java2d.uiScale=2.0 -e "DISPLAY=${DISPLAY}" -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro -v "${XAUTHORITY:-$HOME/.Xauthority}:/.Xauthority:ro" -v davmail.properties/davmail.properties -u "$UID" davmail

Now that you started the container, there should be a new file called davmail.properties. If you stop the container, edit the davmail.properties file and set davmail.mode=O365Manual (or whatever method you want to use, see Exchange protocol), and start the container again (with the same command), everything should be good.

Next, try to connect with your email client, e.g. thunderbird, and set receiving (IMAP) to localhost:1143 and sending (SMTP) to localhost:1025. Both using username <email> and password <password>. Note that <email> has to match the email you want log in to (using oauth2), and <password> can be ANY password, even different than your account password.

After pressing connect on the email client, the GUI from davmail should show instructions on how to authenticate. After following those instructions, stopping the docker container and running cat davmail.properties, there is an entry called davmail.oauth.<email>.refreshToken at the bottom. After copying that entry to your headless instance and restarting the container, configure your email client again. Use vpsip:1143 and vpsip:1025, with username <email> and password <password> (make sure these match the ones used before, but note that can even be different than your actual password).

@mguessan
Copy link
Owner

Awesome, just one quick note: after first connection "something it doesn't matter" password does matter, as we use the provided password to encrypt refresh token.
You should see the davmail.properties updated with an {AES} prefix.

This is to make sure davmail.properties does not contain exploitable secrets and also make sure noone else can connect to your DavMail instance.

@Robin-Sch
Copy link

Robin-Sch commented Feb 17, 2025

Ahh... That explains why I can't send any email I guess

Side note: so what should the password be, the password I provided when generating the token right? Because for reading emails I am using this password, which works. But for sending emails I also use this password, which does not work.

I just re-did the whole thing and everything is working now 🙏

@esabol
Copy link

esabol commented Feb 18, 2025

@Robin-Sch wrote:

chmod +x entrypoint

So the entrypoint script is missing the executable bit in the GItHub repo? That should be fixed.

change DAVMAIL_SERVER to yes in entrypoint

What does that environment variable do and where is it referenced? I don't see it referenced anywhere in the code except for in the entrypoint script. I'm only familiar with the davmail.server=true|false setting in davmail.properties.

Assuming setting this environment variable actually does something, changing

export DAVMAIL_SERVER=no

in the entrypoint script to

export DAVMAIL_SERVER=${DAVMAIL_SERVER:-no}

would allow the same Docker image to be used for both states. I think you could then override the value of DAVMAIL_SERVER by setting the environment variable in the docker run command by including the arguments -e DAVMAIL_SERVER=yes (or whatever the value should be).

What do you think, @Robin-Sch ?

Also, I think you're supposed to use the Makefile in the src/contribs/docker directory. Would typing "make all" in that directory work (if entrypoint was +x)?

@Robin-Sch
Copy link

What does that environment variable do and where is it referenced

It was in the entrypoint so I just changed it. I have no idea what it does/if it even impacts anything

The thing is, there is indeed this davmail.server so I don't think an env variable is needed at all, but I am not sure why @SethRobertson put it in the entrypoint.

For the Makefile I guess it would work? But I didn't try it. Also entrypoint would need +x regardless as it's executed by docker when the container starts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants