Trouble Connecting Email to Gmail Account

Running debug mode logging gave me this:

“TransportException
The connection could not be established with host “ssl://smtp.gmail.com:587”: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:ssl3_get_record:wrong version number”

I tried to change the encryption setting to STARTTLS. This did not fix the issue. Alog with several other changes in settings.

I am able to telnet to smtp.gmail.com (telnet smtp.gmail.com 587)

the SSL version being used by Nextcloud is not compatible with the one Gmail’s server expects.

I know that my password and username are correct.

To correct the issue of " OpenSSL Error messages: error:1408F10B:SSL routines:ssl3_get_record:wrong version number:"
I found this suggestion but I’m not sure if the code is correct or is a good idea

    • Edit config.php: In your Nextcloud’s config.php file, add the following lines:

PHP'mail_smtpstreamoptions' => [ 'ssl' => [ 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT ] ],

I tried searching for other topics to answer this for me. Any help will be appreciated.

My config.php settings:

‘mail_smtpmode’ => ‘smtp’,
‘mail_sendmailmode’ => ‘smtp’,
‘mail_from_address’ => ‘my email - without domain’,
‘mail_smtphost’ => ‘smtp.gmail.com’,
‘mail_smtpport’ => ‘465’,
‘mail_domain’ => ‘gmail.com’,
‘mail_smtpauth’ => 1,
‘mail_smtpname’ => ‘my email’,
‘mail_smtppassword’ => ‘password’,

new message when I changed to port 465

Failed to authenticate on SMTP server with username “my email” using the following authenticators: “LOGIN”, “PLAIN”, “XOAUTH2”. Authenticator “LOGIN” returned “Expected response code “235” but got code “535”, with message “535-5.7.8 Username and Password not accepted. For more information, go to 535 5.7.8 Can't sign in to your Google Account - Gmail Help 5614622812f47-3db1341e15asm1809771b6e.16 - gsmtp”.”. Authenticator “PLAIN” returned “Expected response code “235” but got code “535”, with message “535-5.7.8 Username and Password not accepted. For more information, go to 535 5.7.8 Can't sign in to your Google Account - Gmail Help 5614622812f47-3db1341e15asm1809771b6e.16 - gsmtp”.”. Authenticator “XOAUTH2” returned “Expected response code “235” but got code “334”, with message “334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==”.”.
Sending mail to "Array ( [my email] => user ) " with subject “Email setting test” failed

I also changed my password to a new simpler one to test if this would change anything. I did not, 2-factor is also off

Have you considered to enable 3rd-party app access in Gmail