New to Xwiki - Sending mail errors out with gmail

As I stated above I am brand new to Xwiki and having a devil of a time getting sending of email to work.
I first setup Xwiki via docker and kept having some error issues so I decided to set it up as an LXC container running on a Proxmox server utilizing a Debian 12 template. Install on the LXC container went just fine. I installed Xwiki Debian 16.5.0. with Maria DB. Logs are kept in /var/log/xwiki/2024_6_30.jetty.log (new log for each day).

First thing I did upon setting it up was to make sure me (the only user at this point) was in the XwikiAdminGroup. Second thing I did was change the theme to “Slate”. Third thing I did was try to setup sending mail utilizing my personal gmail account.

Regarding my Gmail account I do have 2 FA authentication active and have other applications that use “App Passwords”. I setup a new “App Password” for Xwiki.

My initial setup was:

property value
server smtp.gmail.com
port 587
username yourusername@gmail.com
password yourpassword or yourapppassword
JavaMail properties mail.smtp.starttls.enable=true

I then went to the home page and tried to “Share by email” to myself. It couldn’t connect. I then ssh’d into the LXC container and successfully pinged “smtp.google.com”. I then used the “dig” command successfully. I did both of these just to prove that I had connectivity.

Then on Stack Overflow I found a post with the following:

openssl s_client -connect smtp.gmail.com:465
HELO smtp.gmail.com 

Then, type “auth login” and you will receive the following: ```
334 VXNlcm5hbWU6

Then it instructs you to put your username (email address) and your password (app password) into a base64 encoder and then enter them one at a time on the command line.  I did this and received a successful with message saying I was accepted.  Proving that you can connect via SSL from the machine.

I tried the same command except substituting port 587 for port 465.  This was successful but because there was no "cipher" it immediately closed the port.  With SSL being successful from the command line I changed my mail setup to the following:
property value
server smtp.gmail.com
port 465
username yourusername@gmail.com
password yourpassword or yourapppassword
JavaMail properties mail.smtp.starttls.enable=true
mail.smtp.auth=true mail.smtp.ssl=true
The above didn't work.  I then entered my username and app password in their respective fields preencoded in base64 and that didn't work either.  The consistent message in the logs is:

> 2024-06-30 17:04:25,275 [qtp2054574951-21 - http://192.168.20.4:8080/xwiki/bin/get/Main/?form_token=DkiI5ha5CmE5OkskjGbiTA&send=1&target=XWiki.crudolphy&target=&includeDocument=link&message=I%20wanted%20to%20share%20this%20page%20with%20you.&xpage=shareinline] ERROR c.x.x.p.m.MailSenderPlugin     - sendEmailFromTemplate: XWiki.SharePage vcontext: org.xwiki.velocity.XWikiVelocityContext@3171936a 
> com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.google.com, 465; timeout -1

So now I am at a loss.  I can connect from the LXC container command line with the my credentials successfully (using SSL and encoding them base64).  I can ping and "dig" smtp.google.com".  Can someone please tell me what I am doing wrong.

Regards
Chuck Rudolphy

I’ve never configured XWiki to use a gmail account using 2FA but I’d expect that this is transparent for the application (i.e XWiki) and that it would still be configured with a username and password (just need to find the right password to use).

Regarding docker, I don’t remember any issue with this (you need ofc to open/map the ports used to send mail).

To test if it works, maybe you could use https://extensions.xwiki.org/xwiki/bin/view/Extension/Mail/MailSenderAPI#HExample1:Sendasimpletextemail instead of share by email (in case it has a problem - I’m mentioning this since share by email is using some older api to send mail but normally it should use the same configuration unless there’s been some migration issue with your wiki at some point).