Email mail settings gives error in nextcloud

Mail Setting does not work and gives this error:

A problem occurred while sending the email. Please revise your settings. (Error: Connection could not be established with host :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution)

I am certain the settings I entered in Nextcloud > Settings > Basic Settings > Email Server
are correct.

from ther server command line I can ping

$ ping 
PING ( 56(84) bytes of data.
64 bytes from ( icmp_seq=1 ttl=105 time=13.3 ms
64 bytes from ( icmp_seq=2 ttl=105 time=14.0 ms

my gmail smtp settings are enabled.

You can try to debug with swaks. (Swiss Army Knife for SMTP).

Login into your GMail account. There you might find in one of the submenus a message, that there was an attempt to login with an unsave mail-client.
Google determines, what save and unsave clients are. You may allow permission through Nextcloud, but it only will work for a couple of weeks. Then it becomes blocked again.